Const template
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Tue Jan 23 19:04:14 PST 2007
Andrei Alexandrescu (See Website For Email) wrote:
> Chris Nicholson-Sauls wrote:
>> So then I ask, why have const constructors/destructors? What, given
>> an (even contrived) example, would be the likely difference in code
>> between constant and non-constant constructors/destructors? And how
>> is this:
>
> A constructor might take different decisions on caching, preallocating
> etc. when it prepares for mutability, as opposed to it knowing that the
> object won't change. For example, creating a const deque might cause a
> different allocation strategy than a non-const one.
>
>> # Foo f = new const Foo;
>>
>> Different from this: # const Foo f = new Foo;
>
> In the latter case you are robbing the constructor from a little piece
> of information. Things will still work.
>
>
> Andrei
I was about to ask the same that Chris N.S. did. So how about a
destructor, what would a const destructor differ from a normal one?
Perhaps to destroy the const object in cases where such object was
created in such a way that the normal destructor no longer correctly
knows how to destroy the const object? Seems reasonable but I can't
think of an example of the top of my head.
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d
mailing list