Const template
Andrei Alexandrescu (See Website For Email)
SeeWebsiteForEmail at erdani.org
Tue Jan 23 13:10:14 PST 2007
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
More information about the Digitalmars-d
mailing list