Boost logo

Boost :

Subject: Re: [boost] detecting a constructor with a specific signature
From: Kenny Riddile (kfriddile_at_[hidden])
Date: 2010-01-28 09:59:46


Kenny Riddile wrote:
> I'm trying to create a type trait to detect the presence of a
> constructor with a very specific signature. Types passed to this trait
> will *always* have a constructor of the form:
>
> T( const std::string& );
>
> but some of them will have this constructor as well:
>
> T( const std::string&, Foo& ); // Second parameter will always be a Foo&
>
> I would like to create a type trait that returns true when the second
> constructor is present. I can't simply do:
>
> !is_convertible<std::string, T>::value
>
> since that will return false when the second constructor is present
> since all Ts are convertible from std::string. Is it possible to create
> such a trait?
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>

Well, I found a compromise that I'm happy with. Since the vast majority
of these types will not have the "extra" constructor, I mandated that
types that do have it derive from a specific type. Then I can simply
use boost::is_base_of to detect them. At least this solution is only
intrusive to types that already desire special treatment. Thanks for
the help guys...looks like I'll have to wait for widespread
std::is_constructible support before revisiting this.


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