I’m trying to understand why not_a_ref is not a reference. I understand that I can make it a reference by auto &. I dug around in the standard for awhile, but got lost and couldn’t figure out where this behaviour is defined.
Example:
#include <vector>
#include <iostream>
#include <type_traits>
std::vector<int> stuff;
std::vector<int>& get_stuff()
{
return stuff;
}
int main()
{
auto not_a_ref = get_stuff();
if( std::is_reference<decltype(not_a_ref)>::value )
std::cout << "is_reference true" << std::endl;
else
std::cout << "is_reference false" << std::endl;
if( ¬_a_ref != &stuff )
std::cout << "definately not a reference" << std::endl;
return 0;
}
From C++11 draft, 7.1.6.4 (
autospecifier) paragraph 6:And from 14.8.2.1 (Deducing template arguments from a function call) paragraph 3:
So the reference is just ignored for the type deduction of
auto.Note how this rule is different from that of
decltype.UPDATE: Please see my comment below, as I think 14.8.2.1 paragraph 3 does not apply.