Hi!
Using mpl in your case is not a lot of work ;) Just use the mpl::set for the set of accepted types and the mpl::has_key meta-function in conjunction with enable_if.
//////////// UNTESTED CODE ////////////////////
#include <boost/utility/enable_if.hpp>
#include <boost/mpl/set.hpp>
#include <boost/mpl/has_key.hpp>
....
typedef set< char,wchar_t> accepted_types;
template<class T>
void foo( T t
, typename
boost::enable_if
<
typename
boost::mpl::has_key<accepted_types, T>::type
>::type* reserved=0
)
{
...
}
/////////////// END OF UNTESTED CODE ////////////////
Good Luck,
Ovanes
Hi,
I have a simple template function that takes one argument. For example:
template< typename t_type >
void foo( t_type param )
{
}
I want to restrict the type of t_type to a certain subset of types, such as 'char' or 'wchar_t'. If the user passes in any type other than those two types, the compiler should not be able to find an overload for foo() that matches the argument types. Note that I would also be using boost::enable_if to test this condition, however I do not see anything in type_traits or anywhere else to perform such a test.
I thought of using mpl::vector to create a list of types the function would take and using enable_if to check if the type is in the container, but this seems like a lot of work. I want to see if there is a simpler, more compact solution.
Thanks.
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users