Boost logo

Boost :

Subject: Re: [boost] detecting a constructor with a specific signature
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-01-27 12:27:43


----- Original Message -----
From: "Kenny Riddile" <kfriddile_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, January 27, 2010 6:14 PM
Subject: Re: [boost] detecting a constructor with a specific signature

>
> Daniel Frey wrote:
>> On 27.01.2010, at 15:52, Kenny Riddile wrote:
>>
>>> Ya, I was already using the "flag typedef" method, but was just wondering if something non-intrusive was feasible...maybe it isn't. A compiler with 0x support isn't an option I'm afraid.
>>
>> No need for C++0x if you only need a special case. Requires a good compiler, though, GCC 4.3 is not good enough, 4.4+ is. The following compiles with GCC 4.4, -ansi -pedantic, replacing decltype with sizeof :)
>>
>> #include <string>
>> #include <iostream>
>>
>> struct Foo {
>> Foo( const std::string& );
>> };
>>
>> struct Bar {
>> Bar( const std::string& );
>> Bar( const std::string&, Foo& );
>> };
>>
>> template< typename T >
>> T make();
>>
>> template< int >
>> struct result { typedef double type; };
>>
>> template< typename T >
>> typename result< sizeof T( make< const std::string& >(), make< Foo& >() ) >::type select( int );
>>
>> template< typename >
>> char select( ... );
>>
>> template< typename T >
>> struct has_foo_ctor
>> {
>> enum { value = sizeof select< T >( 0 ) > 1 };
>> };
>>
>> int main()
>> {
>> std::cout << has_foo_ctor< Foo >::value << std::endl;
>> std::cout << has_foo_ctor< Bar >::value << std::endl;
>> }
>>
>>
>> Regards, Daniel
>>
>> _______________________________________________
>> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>>
>
> Alas, I'm using VC9. The first declaration of select() gives me the
> following error:
>
> error C2564: 'T' : a function-style conversion to a built-in type can
> only take one argument

Hi,

have you tried to double ()

template< typename T >
 typename result< sizeof T(( make< const std::string& >(), make< Foo& >() )) >::type select( int );

Vicente


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