Const template

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Sun Jan 21 10:08:31 PST 2007


Frits van Bommel wrote:
> Andrei Alexandrescu (See Website for Email) wrote:
>> The reflection mechanism would have to provide the information whether
>> or not a given member function changes the object.
>>
>> The only drawback that I can think right now is that the compiler can't
>> exploit this kind of constness with ease to generate better code; it's a
>> "user-space" implementation with semantics that are hard to figure out
>> at the compiler level.
>>
>> A minor drawback is that Const!(Foo) must be implicitly constructible
>> from a Foo, but another in-design language feature (opImplicitCast) will
>> take care of that.
> 
> Correct me if I'm wrong, but I think none of this stuff will work for 
> methods that are only declared instead of defined as well; 'const', 
> implemented like this, wouldn't work for "header modules"...

That is correct. Interface functions, nonfinal methods, and 
declared-only functions must be annotated manually. The same holds for 
things like "pure". Hopefully they are only a fraction of the entire 
const use, such that the burden of the programmer is reduced.


Andrei



More information about the Digitalmars-d mailing list