www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Storing temp for later use with ranges

reply DigitalDesigns <DigitalDesigns gmail.com> writes:
Does ranges have the ability to store a temp value in a "range 
like way" that can be used later?

The idea is to avoid having to create temp variables. A sort of 
range with "memory"
Jun 15 2018
parent Timoses <timosesu gmail.com> writes:
On Saturday, 16 June 2018 at 01:53:15 UTC, DigitalDesigns wrote:
 Does ranges have the ability to store a temp value in a "range 
 like way" that can be used later?

 The idea is to avoid having to create temp variables. A sort of 
 range with "memory"
I believe that if the range is a forward range you can use the `.save` method to get a copy of the range in its current state. Take a look at https://dlang.org/phobos/std_range_primitives.html#isForwardRange and https://dlang.org/phobos/std_range_interfaces.html#ForwardRange
Jun 15 2018