Boost logo

Boost :

Subject: Re: [boost] [range] [extensions] Default values for range access adaptors?
From: Yusuke Ichinohe (valp_ab_at_[hidden])
Date: 2013-06-07 15:41:25


Hi Michel, Akira,

I think simpler solution would be to add range support for
boost::optional in additional header (e.g.
<boost/range/range/optional.hpp>).
i.e. boost::optional will become random access range.

// OK
#include <boost/range/range/optional.hpp>
for (T x : r | optional_front()) {
  std::cout << x << std::endl
}

// also OK
if (optional<T> x = r | optional_front()) {
  std::cout << x.get() << std::endl;
}

// another example:
#include <boost/range/range/optional.hpp>
optional<int> x = 100;
assert(boost::size(x) == 1);
optional<int> y = boost::none;
assert(boost::size(y) == 0);

Thanks.

2013/6/6 Akira Takahashi <faithandbrave_at_[hidden]>:
> Hi Michel,
>
> 2013/6/6 Michel Morin <mimomorin_at_[hidden]>
>
>> Akira Takahashi wrote:
>> > My Boost.Range Extension has `front` accessor.
>>
>> "Range Access" adaptors in your extensions are interesting.
>> For the consistency of range adaptors, shouldn't `front` adaptor
>> return `single` range?
>>
>
> I see. `optional_front` usage is following:
>
> if (optional<T> x = r | optional_front()) {
> std::cout << x.get() << std::endl;
> }
>
> If `front` return signle range, the usage is following:
>
> for (T x : x | front) {
> std::cout << x << std::endl;
> }
>
> If `front` is error, the return value is empty range.
> I think single range approach is better. However, I think now `front` and
> `optional_front` is useful.
>
> I would like to add `optional_front` and `front_range`.
>
> Thanks!
> Akira

--
' Yusuke Ichinohe
' yusuke.ichinohe_at_[hidden]

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk