
I just added my second metafunction of the form is_range_of_X<T> for use with enable_if, and although the first one took some fiddleing to pass both compilers I was using, the second was a clone of the first with the name and type changed. So it really ought to be a general purpose is_range_of<Whatever, T> metafunction. I would suggest that such a thing be added to the Range library. It is meant for overloaded forms that operate on ranges, and you don't want to accept just any ol' thing because, perhaps, you want other overloads or to get better error messages for bad arguments. A typical example would be something like: void insert (const C& x); template <typename R> typename enable_if<typename is_range_of<C,R>::type, void>::type insert (const R& range) { ⋯ } In my case, I check whether R is indeed a Range (something that appears at first to be missing from the library too, but has_range_iterator is probably what is really meant by that) and the underlying element is convertible to the desired type. In a general-purpose library you might need to put more thought into what tests are so common as to be worth reusing at that level. I think having convertable-to-C (where you just give C) and another one which lets you pass in another metafunction for matching the element would allow reuse of experly written common code that takes care of nuances across compilers, e.g. choking on value_type if the outer is NOT a range, so you need to ensure short-circuit evaluation of the meta-expression. —John

On 23/01/13 17:39, John M. Dlugosz wrote:
I just added my second metafunction of the form is_range_of_X<T> for use with enable_if, and although the first one took some fiddleing to pass both compilers I was using, the second was a clone of the first with the name and type changed. So it really ought to be a general purpose is_range_of<Whatever, T> metafunction.
I assume it it's simply something like is_same<typename mpl::eval_if< is_range<T>, range_value<T>, void>::type, Whatever> ?
participants (2)
-
John M. Dlugosz
-
Mathias Gaunard