| |
| Posted by Alexandru Ermicioi in reply to Andrei Alexandrescu | PermalinkReply |
|
Alexandru Ermicioi
Posted in reply to Andrei Alexandrescu
| On Tuesday, 2 November 2021 at 20:17:06 UTC, Andrei Alexandrescu wrote:
> On 2021-11-02 15:32, Adam D Ruppe wrote:
>> On Tuesday, 2 November 2021 at 18:09:55 UTC, H. S. Teoh wrote:
>>> Why is this necessary? I thought we're getting rid of std.range.interfaces.
>>
>> It is actually really, really, useful. If phobos didn't offer it, someone would reinvent it anyway.
>>
>> (In fact, there's a lot of cases where using them is more efficient than generating more and more code...)
>
> Yah, polymorphism has its place. The only problem is passing around reference ranges. They should have a thin struct wrapper that carries the proper copy semantics.
So, if forward range interface (from std.range.interfaces) is to be kept in phobos, it should provide a .save method, that can be used instead of copy constructor.
Then, it is possible to have only one wrapper struct for transforming it into value type (i.e. behave same as struct forward range), that would use .save when wrapper's copy constructor is invoked. It would allow to use this wrapper as part of method parameter type, in order to enforce people using it, and not randomly forgetting to wrap it.
|