
Hello, 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? Regards, Alexander --------------- sample code ------------ #include <boost/static_assert.hpp> #include <boost/utility/enable_if.hpp> #include <boost/type_traits.hpp> struct Data { virtual foo() =0; }; int main(int argc, char* argv[]) { BOOST_STATIC_ASSERT((boost::is_convertible<Data,Data>::value)); return 0; } --------------- sample code ------------ __________________________________ Do you Yahoo!? Yahoo! Small Business - Try our new resources site! http://smallbusiness.yahoo.com/resources/

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?
This is a tricky one; first the headline news: current cvs will compile that, and will report false whenever the "To" type is abstract, but only if you have a newish compiler that supports is_abstract. The reason for returning false, is that nothing is ever convertible to an abstract type, since no object of an abstract type can ever be created. Now for the problem: is general is_convertible<A,A> may not compile if A's copy-constructor is non-public. We'd love to be able to fix that, but no one knows how to detect whether a member is accessible or not. HTH, John.

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@yandex.ru

if static From _m_from; is replaced by static const From& make_from();
it'll work with abstract types
That would stop working for reference types. However this change is already unnecessary: an add_reference is applied before the code gets that far, so abstract types *are* allowed as the "From" parameter, and have been for some time (as are other tricky things like function types), and this is currently tested in our test suite. It's when the "To" parameter is an abstract type that things get tricky, and as I said, this is also fixed in current cvs: provided your compiler supports is_abstract. The remaining issue, is that there is no way to tell whether a converting-constructor is accessible or not, so if the "To" type has a private converting constructor that accepts the "From" type, then the result is that is_convertible produces a compiler error. As far as anyone knows there is no way around that - feel free to consider that a challenge if you like :-) John.
participants (3)
-
John Maddock
-
Me here
-
Nick Tchistiakov