Boost logo

Boost Users :

From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-01-29 12:18:03


AMDG

cp now wrote:
> 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<pair<int, int>, int> is convertible to a plain old pair<int,
> int>, but the compiler (and this coder) takes a different view...

It's impossible to make it work in the general case.
boost::is_convertible only checks whether
there is a non-explicit constructor. To make the check work, we would
need to somehow
instantiate the constructor and detect whether compiling it succeeded of
not. There is no way
to do this in C++.

Not possible:

template<class T, class U>
struct is_convertible_impl {
    static_try {
        U u = T();
        typedef true_type type;
    } catch(compilation_error&) {
        typedef false_type type;
    }
}

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net