This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
std::ref( int ) gives double& ?
- From: michel <20michel13 at gmail dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Sun, 07 Apr 2013 18:59:55 -0400
- Subject: 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