std::ref( int ) gives double& ?

michel 20michel13@gmail.com
Sun Apr 7 23:00:00 GMT 2013


hello,
I thought std::ref(int) would become something like int& but it seems 
double&...If any one could explain the why std:ref(int)seems to become a 
double& somehow in the example below, thank you.
Here is the test code, command line, and output (Using g++ 4.7.2):

#include <iostream>
#include <functional>

using namespace std;
template <typename T> void foo_impl(T val, true_type)
{
     cout << "someone interested by integral values "<<val<<endl;
}

template <typename T> void foo_impl(T val, false_type)
{
     cout << "someone interested by floating values "<<val<<endl;
}
template <typename T> void foo_impl(T val)
{
     foo_impl(val, std::is_integral<T>());
}

int main()
{
     int x = 12;
     foo_impl(x);
     foo_impl(std::ref(x));
}

michel@PC:$ g++ -std=c++11 -Wall -Wextra  wrapper.cpp
michel@PC:$./a.out
someone interested by integral values 12
someone interested by floating values 12


thanks,
michel



More information about the Libstdc++ mailing list