In general, who should do more work: popFront or front?
surlymoor
surlymoor at cock.li
Tue Jun 15 05:35:52 UTC 2021
On Tuesday, 15 June 2021 at 05:17:06 UTC, mw wrote:
> I think there is another convention (although it's not formally
> enforced, but should be) is:
>
> -- `obj.front() [should be] const`, i.e. it shouldn't modify
> `obj`, so can be called multiple times at any given state, and
> produce the same result
> -- `obj.popFront()` perform the actual mutation of the internal
> state the `obj`, each invocation will change the object's state
> once.
That's a separate matter. To use as an example once more,
MapResult's front method produces the range's elements, and its
invocation results in the identical element given that popFront
isn't called; it doesn't affect the range's source. It satisfies
those expectations, but it leaves wanting to know whether one
should strive for front being inexpensive to call.
My original question is stupid, and I think I'm just going to
have to experiment.
More information about the Digitalmars-d-learn
mailing list