Difference between range `save` and copy constructor

uranuz neuranuz at gmail.com
Sun Feb 16 09:45:06 UTC 2020


Also I see the problemme that someone can think that it creates 
an input range, because he doesn't provide `save` method, but 
actually it creates forward range unexpectedly, because it is 
copyable. And it makes what is actually happening in code more 
difficult. Some algrorithm can take ranges by value, but others 
take them by reference. So result can be completely different. In 
first case range is being consumed, but in another in is not. 
Personally I prefer to take range by reference in all of my 
algrorithms except cases where I is always a class (because it's 
a reference already). But I still don't know what is the right 
way. There are no official guidelines about it. So every time 
it's a problemme. Although it looks like that range is a simple 
concept, but it's actually not.


More information about the Digitalmars-d-learn mailing list