Boost logo

Boost Users :

Subject: [Boost-users] Range library suggestion
From: John M. Dlugosz (mpbecey7gu_at_[hidden])
Date: 2013-01-23 11:39:03


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


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