On 02/05/2012 22:01, Jacob Carlborg wrote:
Is there a general function for transforming a range back to the original type? 
If not,
would it be possible to create one?

To sum it up, it can't be done in the general case. The range API doesn't know or care about the underlying data structure. That's half the point of it. The underlying data structure might not even exist. An example is a range used as a file stream, a random number generator or to lazily generate a mathematical sequence.

Moreover, what would you want such a function to return if the range is:
- a file stream with a cache
- an array wrapper to loop infinitely through it?
- a concatenation of ranges that may be of different types?

Moreover, even if there were some "range with an underlying container" classification, it would be an extra burden on the writer of the range wrapper to implement this.

If you want to generate a range that views a container in a certain way, and then construct a container of the original type (or indeed any type) from that range, then create the container and then use a foreach loop on the range (or a .save of it, if you want to keep the range afterwards) to put the data into the container.

Stewart.

Reply via email to