|
Boost Users : |
From: MB (mb2act_at_[hidden])
Date: 2005-12-06 23:30:59
Victor A. Wagner Jr. wrote:
> After reading (and re-reading a few times) the documentation on
> range, it appears to me that there is little (if any) difference between:
> boost::sub_range<T>
> and
> boost::iterator_range<T::iterator>
>
> I've been working on a N way merge algorithm for work, and thought it
> might be a nice chance to learn bost::range and maybe even get it
> general enough to submit for boost utility some day.
> At any rate. Here's the problem: I've written a test case and two
> implementations (work still in progress) but I get compile errors
> when I try to use sub_range.
>
> the code can be found at http://www.noidea128.org/sourcefiles/15646~
>
> to change the program from compiling/running the iterator_range to
> sub_range simply change the lne from:
>
> Nway_merge(contain, ourmerged);
> -to-
> SNway_merge(contain, ourmerged);
>
> my compiler (VC-8_0) gives two errors which I cannot decipher.
> Any assistance would be appreciated.... especially if I've
> misunderstood why sub_range instead of iterator_range.
Hi,
push_back adds constness to sub_range.
See:
#include <vector>
#include <boost/range/sub_range.hpp>
typedef std::vector<int> container;
boost::iterator_range<container::iterator> iterng;
boost::sub_range<container> subrng;
void push_to_iterng(const boost::iterator_range<container::iterator>& rng)
{
iterng = rng;
}
void push_to_subrng(const boost::sub_range<container>& rng)
{
// error
subrng = rng;
}
GCC can skip the work for constness if the target type is the same,
so GCC compiles successfully.
But I think it should be conceptually error.
On the other hand, constness of iterator_range has no effect.
Some situations add constness to range before one knows, so
it is preferable to avoid using sub_range as value.
sub_range is maybe for clients.
For example, you can see Boost.StringAlgorithm.
They return iterator_range, but you can catch it by using sub_range.
Regards,
MB
http://p-stade.sourceforge.net/
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