#include <iostream>
int main()
{
int lvalue = 4 ;
int & rvalue = lvalue;
auto lvalue2 = rvalue;
decltype(auto) rvalue2 = rvalue;
std::cout << (&lvalue == &rvalue ) << " ";
std::cout << (&lvalue == &rvalue2) << " ";
std::cout << (&lvalue == &lvalue2) << " ";
std::cout << std::endl;
return 0;
}
// Output: 1 1 0
Reference: https://en.wikipedia.org/wiki/C%2B%2B14#Alternate_type_deduction_on_declaration.5B5.5D
Monday, September 25, 2017
C++14: Alternate type deduction on declaration
C++14 added the combined decltype(auto) in order to be able to deduce a reference type. Here is an example:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment