[range] extension proposal - construct

Hi, I have a proposal for addition to Boost.Range library: template<typename RangeT, typename OtherRangeT> RangeT construct<RangeT>(const OtherRangeT& Source); template<typename RangeT, typename IteratorT> RangeT construct<RangeT>(IteratorT From, IteratorT To); Both functions should construct a range of type RangeT, that will contain elements from Source or [From,To) respectively. Motivation: In the standard library Sequence concept defines a way for constructing a sequence from and arbitrary range of iterators. This is very useful concept and it would be nice to have something similar available in the Range library. Most significant advantage of this construct is that it allows to create algorithms, that modify an input range and return a copy of it. Currently there is no generic way for constructing or modifying a range, therefor it restricts the usage of range to non-mutable input parameters. For instance a simple to_lower algorithm (available in StringAlgo library) template<typename SequenceT> SequenceT to_lower_copy(const SequenceT& Input, const std::locale& Loc=std::locale()); requires the input to satisfy sequence requirements so it can construct the result. This effectively disables many advantages of Range library. Because it is not possible to adapt an external class (like CString) to work with this algorithm. Yes it could be very easy to implement construction for this class. There is already a similar function in the range library. It's called copy<> but, this function is provided solely for sequences and there is no feasible and documented way for customization. Best Regards, Pavol

Pavol Droba wrote:
Hi,
I have a proposal for addition to Boost.Range library:
template<typename RangeT, typename OtherRangeT> RangeT construct<RangeT>(const OtherRangeT& Source);
template<typename RangeT, typename IteratorT> RangeT construct<RangeT>(IteratorT From, IteratorT To);
Both functions should construct a range of type RangeT, that will contain elements from Source or [From,To) respectively.
Motivation:
In the standard library Sequence concept defines a way for constructing a sequence from and arbitrary range of iterators. This is very useful concept and it would be nice to have something similar available in the Range library.
Yes, I already proposed this and use if frequently.

"Pavol Droba" <droba@topmail.sk> wrote in message news:20050822095022.GC8823@lenin.felcer.sk...
Both functions should construct a range of type RangeT, that will contain elements from Source or [From,To) respectively.
Motivation:
In the standard library Sequence concept defines a way for constructing a sequence from and arbitrary range of iterators. This is very useful concept and it would be nice to have something similar available in the Range library.
Most significant advantage of this construct is that it allows to create algorithms, that modify an input range and return a copy of it.
Currently there is no generic way for constructing or modifying a range, therefor it restricts the usage of range to non-mutable input
right. a range is not copyable, so we need a new concept. parameters.
For instance a simple to_lower algorithm (available in StringAlgo library)
template<typename SequenceT> SequenceT to_lower_copy(const SequenceT& Input, const std::locale&
Loc=std::locale());
requires the input to satisfy sequence requirements so it can construct
the result.
This effectively disables many advantages of Range library.
by this you mean that the sequence requirement is too strict?
Because it is not possible to adapt an external class (like CString) to work with this algorithm. Yes it could be very easy to implement construction for this class.
then what about a CopyableRange concept?
There is already a similar function in the range library. It's called copy<> but, this function is provided solely for sequences and there is no feasible and documented way for customization.
do you want ADL customization like as with the other functions? br -Thorsten

On Mon, Aug 22, 2005 at 05:50:30PM +0200, Thorsten Ottosen wrote:
"Pavol Droba" <droba@topmail.sk> wrote in message news:20050822095022.GC8823@lenin.felcer.sk...
[snip]
Most significant advantage of this construct is that it allows to create algorithms, that modify an input range and return a copy of it.
right. a range is not copyable, so we need a new concept.
precisely.
Currently there is no generic way for constructing or modifying a range, therefor it restricts the usage of range to non-mutable input parameters.
For instance a simple to_lower algorithm (available in StringAlgo library)
template<typename SequenceT> SequenceT to_lower_copy(const SequenceT& Input, const std::locale& Loc=std::locale());
requires the input to satisfy sequence requirements so it can construct the result. This effectively disables many advantages of Range library.
by this you mean that the sequence requirement is too strict?
Sequence requires also a bunch of other members. Also it is purely defined in the terms of member functions. So at least we need an external alternative.
Because it is not possible to adapt an external class (like CString) to work with this algorithm. Yes it could be very easy to implement construction for this class.
then what about a CopyableRange concept?
Sounds fine.
There is already a similar function in the range library. It's called copy<> but, this function is provided solely for sequences and there is no feasible and documented way for customization.
do you want ADL customization like as with the other functions?
I'd like to see a documented way for customization. Unless there is a good reason for it, it should like like the functions that are already there like begine and end. Regards, Pavol
participants (3)
-
Neal Becker
-
Pavol Droba
-
Thorsten Ottosen