Why in Phobos is empty() sometimes const and sometimes not

Matt gamblemj at gmail.com
Mon Jul 29 21:11:45 UTC 2019


On Monday, 29 July 2019 at 19:38:34 UTC, Jonathan M Davis wrote:
> On Monday, July 29, 2019 11:32:58 AM MDT Matt via 
> Digitalmars-d-learn wrote:
>

>
> Because const ranges are basically useless, there really isn't 
> much point in putting const on any range functions even if it 
> would work for that particular range, and if a range is a 
> wrapper range, the only way that it could do it would be if it 
> used static if to make the code differ depending on whether the 
> range it's wrapping will work if that function is const, which 
> essentially means duplicating a bunch of code for little to no 
> benefit.
>
> - Jonathan M Davis

This was super helpful, thanks so much. I thought it was good 
practice to label member functions const if they didn't/couldn't 
modify any data. Now I see the reality is different for ranges. 
Not worrying about const for these seems simpler than code 
repetition.

Thanks again.



More information about the Digitalmars-d-learn mailing list