Angus Leeming
Is it possible to use enable_if with a constructor?
In principle, yes. You just add a dummy default parameter for the enabler.
For example, I'd like to define a constructor that allows only certain values of an enum:
No chance; that's a runtime test... or you'd have to specify the enum
as a template argument to the ctor explicitly... but you can't provide
explicit template arguments to ctors.
Well, you can do something like:
template <class N>
foo(
N
, typename boost::enable_if<
typename contains_c<
mpl::vector_c >::type
, typename mpl::end<S>::type
>
>
{};
and then a foo is constructed something like this:
foo x( mpl::int_<state2>() );
HTH,
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com