The type_traits library gives me somewhat erroneous answers when dealing
with pairs of pairs.
The following code produces the errors below, but interestingly, the
BOOST_ASSERT actually succeeds. It seems is_convertible thinks a
pair, int> is convertible to a plain old pair, but
the compiler (and this coder) takes a different view...
#include <utility>
#include
#include
std::pair go(std::pair p) {
return p;
}
int main()
{
BOOST_STATIC_ASSERT((
boost::is_convertible<
std::pair<
std::pair,
int
>,
std::pair
>::value
));
std::pair, int> p1 =
std::make_pair(std::make_pair(1,2),3);
std::pair p2 = go(p1);
return 0;
}
$ g++-4.1.1 test.cpp -I/usr/include/boost-1_33_1
/home/vsekhar/gcc-4.1.1/lib/gcc/i686-pc-cygwin/4.1.1/../../../../include/c++/4.1.1/bits/stl_pair.h:
In constructor 'std::pair<_T1, _T2>::pair(const std::pair<_U1, _U2>&) [with
_U1 = std::pair, _U2 = int, _T1 = int, _T2 = int]':
test.cpp:25: instantiated from here
/home/vsekhar/gcc-4.1.1/lib/gcc/i686-pc-cygwin/4.1.1/../../../../include/c++/4.1.1/bits/stl_pair.h:90:
error: cannot convert 'const std::pair' to 'int' in initialization
The compiler appears to be attempting a piecewise conversion of the contents
of the pair, hence the error about converting pair to 'int' rather
than an error about converting pair, int> to pair.
Is there a method of converting that is_convertible has in mind when it
returns true for the aforementioned conversion? I'm testing here for simple
implicit conversion...
-v