Article: Why Const Sucks

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Mar 6 18:47:36 UTC 2018


On Tue, Mar 06, 2018 at 01:31:39PM -0500, Steven Schveighoffer via Digitalmars-d-announce wrote:
> On 3/6/18 10:39 AM, Jonathan M Davis wrote:
> > Yeah. If you're dealing with generic code rather than a specific
> > range type that you know is implicitly saved when copied, you have
> > to use save so often that it's painful, and almost no one does it.
> > e.g.
> > 
> > equal(lhs.save, rhs.save)
> > 
> > or
> > 
> > immutable result = range.save.startsWith(needle.save);
> 
> Yep. The most frustrating thing about .save to me is that .save is
> nearly always implemented as:
> 
> auto save() { return this; }
> 
> This just screams "I really meant just copying".

Yeah, and also:

	auto save() {
		auto copy = this;
		copy.blah = blah.dup;
		return this;
	}

Which just screams "I'm really just a postblit in disguise".


T

-- 
This is not a sentence.


More information about the Digitalmars-d-announce mailing list