|
Boost Users : |
Subject: [Boost-users] [enable_if] How to enable a constructor
From: Michael Kaes (michael.kaes_at_[hidden])
Date: 2011-03-29 05:51:50
Hi all,
I am playing around with enable_if and I want to create a constructor switch.
The code is the following:
------------------------------------------------
struct NullType{};
struct TestType{};
struct NonNull{};
template<typename T, typename U = NullType>
struct TemplateStruct
{
TemplateStruct(int i, typename boost::enable_if<boost::is_same<U,
NullType>, void* >::type dummy = 0)
{
std::cout << "One Param == " << i << std::endl;
}
TemplateStruct(int i, int j, typename
boost::disable_if<boost::is_same<U, NullType>, void* >::type dummy =
0)
{
std::cout << "Two Param == " << i << "," << j << std::endl;
}
};
int main(int /*argc*/, char**)
{
TemplateStruct<TestType>(1);
TemplateStruct<TestType,NonNull>(1,2);
return 0;
}
-------------------------------------
I want that the first Ctor is only available when a NullType is passed
in and if not that the second one is available but not the first.
I don't want to do a class specialization because the class is rather
big and extracting all the methods to a common class would be
difficult.
So how can I reuse the template parameter U for the Ctors enable_if?
Or is this simply not possible?
Regards,
Michael
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net