Do we need a time-out in D evolution?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Sun Jun 10 06:17:30 PDT 2007


gareis wrote:
> Sean Kelly wrote:
>> I'll admit that one of my reservations about 'const' is the need to 
>> potentially write twice as many class methods.  I don't suppose 
>> there's any way around this?
> 
> Either you need to modify your function's parameter, in which case you 
> can't write a const version, or you don't need to modify your function's 
> parameter, in which case you just pass it in as const.
> 
> So how do you need to write additional methods?

When the return value should have a different type depending on the 
types of the parameters and/or "this"?
For instance, when you want to return a slice of a string you might want 
the slice to have the same "constness" as one of the parameters (or 
"this" in case of a String class). This would require either overloading 
on constness (i.e. extra methods) or perhaps some template magic. The 
latter option might not be available if you need the method(s) to be 
overridable, by the way.
Also, it might even be triple the methods in some cases: 
mutable/const/invariant.



More information about the Digitalmars-d mailing list