This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

std::ref( int ) gives double& ?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]