I need a metafunction that returns true iif a type has a constructor with 2
arguments of a given type. Does mpl have it? If not, is it possible to
implement?
template
on Fri Mar 13 2009, Roman Perepelitsa
I need a metafunction that returns true iif a type has a constructor with 2 arguments of a given type. Does mpl have it? If not, is it possible to implement?
template
struct is_constructible_from; struct foo { foo(int, int); }; struct bar { bar(int*, int); }; struct baz {};
int main() { assert(is_constructible_from
::value); assert(is_constructible_from ::value); assert(!is_constructible_from ::value); assert(!is_constructible_from ::value); };
I know of no way to do that. -- Dave Abrahams BoostPro Computing http://www.boostpro.com
Some time ago, I needed a trait is_copy_constructible, which is a special
case of is_constructible_from. I remeber to have some thought, that if C++
would support injected friends it might be possible to calculate. But that
was really tricky solution and I just posponed it until the compilers
support injected friends (due to the upcoming standard). At least MSVC 9
supports it now and I think we could try solving it, may be for the first
for copy constructible trait and later generalize it.
On Tue, Mar 17, 2009 at 4:50 PM, Steven Watanabe
AMDG
How do you get an expression to have a different type depending on whether a given class has a particular constructor?
In Christ, Steven Watanabe
Roman Perepelitsa wrote:
I need a metafunction that returns true iif a type has a constructor with 2 arguments of a given type. Does mpl have it? If not, is it possible to implement?
As has been explained it's impossible. However, if you change the construction syntax of your objects you could do it. If you made the constructors private or protected and provided a static function for building them you'd have something that can be tested with metaprogramming. Not saying this will help you, but it's an idea.
Since it's impossible to implement is_constructible_from for constructors with two arguments, I'll go with a workaround that does not require me to have such metafunction. Thanks to everyone who replied! Roman Perepelitsa.
participants (6)
-
David Abrahams
-
joel falcou
-
Noah Roberts
-
Ovanes Markarian
-
Roman Perepelitsa
-
Steven Watanabe