Is there, or how would you write, a metafunction class that tests whether a class is compatible with boost::range
? I want to use the boost::enable
idiom, something like
template <typename T>
Constructor::Constructor(const T& t, __attribute__((unused)) typename boost::enable_if<is_range_compatible<T> >::type* aux=NULL)
for an appropriate is_range_compatible
metafunction. I know about is_container from pretty_print, which captures a lot of cases, but not everything that works with boost::range
.
Edit This is using C++03, so I don't have access to C++11 features. I'm using an old, gcc 4.1, and boost 1.51.
If you upgrade to Boost 1.54, there is a nice library called TTI. It allows you to compose type traits introspection meta functions at will, so that you can easily spin off you own meta predicates which can be used to enable or disable function templates. Though it is a nice meta programming exercise, I don't recommend to do that in production code. I found it hard to catch the "false negatives" which arise from implementation details of STL containers. For example, the associative containers coming with MSVC11 inherit their
begin
andend
member functions from a base class which yields false negative with meta predicates generated viaBOOST_TTI_HAS_MEMBER_FUNCTION
. Despite of his nickname, Useless gave you a good advice: Use concepts coming with Boost.Range to reject or accept the type inside the body of the function template such as the constructor in your example... Of course, this will not solve the convertibility problem for yourConstructor
...EDIT: example, taken from vex: