Boost logo

Boost :

From: Nick Tchistiakov (kolach56_at_[hidden])
Date: 2005-03-25 10:46:38


Hello John,

Thursday, March 24, 2005, 8:23:00 PM, you wrote:

>> The code below does not compile, when, I believe, it
>> should. Compiler says that you can't instantiate
>> abstact class.
>>
>> I'm really surprised - it is trivial use case, but I
>> did not find a problem report. Do I miss something?

JM> This is a tricky one; first the headline news: current cvs will compile
JM> that, and will report false whenever the "To" type is abstract, but only if
JM> you have a newish compiler that supports is_abstract. The reason for
JM> returning false, is that nothing is ever convertible to an abstract type,
JM> since no object of an abstract type can ever be created.

JM> Now for the problem: is general is_convertible<A,A> may not compile if A's
JM> copy-constructor is non-public. We'd love to be able to fix that, but no
JM> one knows how to detect whether a member is accessible or not.

JM> HTH,

JM> John.

JM> _______________________________________________
JM> Unsubscribe & other changes:
JM> http://lists.boost.org/mailman/listinfo.cgi/boost

from is_convertable.hpp

template< typename From >
struct does_conversion_exist
{
    template< typename To > struct result_
    {
        static no_type BOOST_TT_DECL _m_check(...);
        static yes_type BOOST_TT_DECL _m_check(To);
        static From _m_from;
        enum { value = sizeof( _m_check(_m_from) ) == sizeof(yes_type) };
    };
};

if
static From _m_from;
is replaced by
static const From& make_from();

it'll work with abstract types

template< typename From >
struct does_conversion_exist
{
    template< typename To > struct result_
    {
        static no_type BOOST_TT_DECL _m_check(...);
        static yes_type BOOST_TT_DECL _m_check(To);
        static const From& make_from();
        enum { value = sizeof( _m_check(make_from()) ) == sizeof(yes_type) };
    };
};

-- 
Best regards,
 Nick                            mailto:kolach56_at_[hidden]

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk