Akira Takahashi wrote:
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.
This looks like `taken(1)`. Considering the fact that `container.front()` assumes `rng` is not empty, I came up with another idea: implementing `front` as a range-unchecking version of `taken` (`front(n)` requires that the range has length at least n), and `front` defaults to `front(1)`. (BTW, the documentation says that `taken` returns BidirectionalRange, but I believe `taken` returns ForwardRange.)
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`.
IMO, your `front` and `optional_front` are not range adaptors; they're range functions that use a pipe operator. Because they introduce a new syntax to Boost.Range, it would be better to make discussions about this syntax in a new thread. If this new syntax is accepted, then it is natural to expect that other range functions (size, all_of, etc.) are also supported. Regards, Michel