std.range.cacheFront proposal&working code: wraps a range to enforce front is called only once
Chris
wendlec at tcd.ie
Thu Oct 24 08:36:58 PDT 2013
On Thursday, 24 October 2013 at 01:48:32 UTC, Jonathan M Davis
wrote:
> On Tuesday, October 22, 2013 23:40:00 Timothee Cour wrote:
>> Following the recent thread "front evaluated multiple time
>> with joiner
>> depending on where extra arg given", I'd like to propose the
>> following
>> addition in std.range :
>>
>> The goal is to ensure that a given range's 'front' method is
>> called only
>> once per element, allowing one to handle safely side effects
>> in 'front'
>> methods
>
> Considering that front really isn't supposed to have side
> effects, I'm inclined
> to think that putting something like this in the standard
> library is a bad
> idea. It just encourages bad code. There's certainly no reason
> why you can't
> implement it for your own stuff if you want to, but I don't
> think that it's
> something that should be encouraged as it goes against the
> range paradigm. The
> getter property for front really should be logically const and
> logically pure,
> and a front with side effects should be something reserved for
> debugging.
>
> - Jonathan M Davis
How do you define side effects? After all ranges manipulate,
reformat or restructure data.
More information about the Digitalmars-d
mailing list