
I'd be surprised if others haven't needed this. While range comes with an adapter for plain old C array, it doesn't come with an adapter from that other (probably more common!) kind of plain old C array: a pointer and length. This seems useful. Maybe add to examples?

Yep. And, as you've guessed, I bodged it.
This seems useful. Maybe add to examples?
Yep. But it would be even more useful with several explanatory comments (and copyright author and a Boost license text) ;-) Paul --- Paul A. Bristow Prizet Farmhouse Kendal, UK LA8 8AB +44 1539 561830, mobile +44 7714330204 pbristow@hetp.u-net.com

Neal Becker wrote:
OK, how about the attached?
In your attached example, int main () { double x[10]; for (int i = 0; i < 10; ++i) x[i] = i; double y = sum (make_array_range (x, 10)); std::cout << y << '\n'; } You could write instead of writing make_array_range(x, 10): - x (arrays are ranges) - as_array(x) (as_array is a no-op here, this function is only useful for arrays of chars which are a special case) - make_iterator_range(x, x+10) (the general-purpose mechanism to define ranges from iterators)

Mathias Gaunard wrote:
You're correct, I could just use: sum (boost::make_iterator_range (x, x+size)); But, these don't compile: sum (boost::make_iterator_range<double const*> (x, x+size)); sum (boost::make_iterator_range<double *> (x, x+size)); I'm stumped. The reason I need this, is I will need the type of range returned by boost::make_iterator_range (double*, double*). Apparantly, it's not boost::iterator_range<double*>.

Neal Becker wrote:
That's because there are different overloads of make_iterator_range. You're not supposed to specify any template parameter, since the point of all make_* functions is to deduce these automatically. If you want to specify them, then use the constructor of iterator_range directly.
make_iterator_range(double*, double*) does return an iterator_range<double*>.
participants (3)
-
Mathias Gaunard
-
Neal Becker
-
Paul A. Bristow