Should the "front" range primitive be "const" ?
Steven Schveighoffer
schveiguy at yahoo.com
Wed Jan 31 16:58:38 UTC 2018
On 1/30/18 8:05 PM, Jonathan M Davis wrote:
>
> Except that unless front returns by ref, it really doesn't matter whether
> front is const unless it's violating the range API, since front is supposed
> to return the same value until popFront is called (or if it's assigned a new
> value via a front that returns by ref). So, in practice, putting const on
> front really doesn't help you any, and it actually hurts you for range
> composability.
Right, but that is the difference between a convention ("front is
supposed to...") vs. a compiler-enforced guarantee (modifying data by
calling a const-tagged front is a compiler error).
If you are OK with conventions, you don't need const at all.
-Steve
More information about the Digitalmars-d-learn
mailing list