this(this) must be cheap and O(1)

Michel Fortin michel.fortin at michelf.com
Sun Sep 25 05:44:39 PDT 2011


On 2011-09-25 02:52:47 +0000, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

> On 9/24/11 9:31 PM, Michel Fortin wrote:
>> Perhaps I am missing the point. What would be gained by forcing
>> this(this) to be nothrow?
> 
> It further frees the standard library to cater for the throwing case.

Concretely, what does it simplifies?

Does it only simplifies the documentation of algorithms? … in that most 
algorithms doing copies should mention that throwing during copy may 
leave some mutated data structure in some kind of a half processed 
state. I don't think that would surprise anyone.

That said, I would certainly recommend not throwing inside this(this), 
but I don't think this recommendation should be enforced by the 
language. I think forcing it to be nothrow would encourage people to 
silently ignore exceptions with try {…} catch (…) {}. Unless you catch 
all exceptions like that, nothrow will prevent you from calling many 
functions which could be reasonable to call otherwise, such as writeln, 
or from incrementing a reference counter checking for overflow.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list