Logical const
Jonathan M Davis
jmdavisProg at gmx.com
Tue Nov 30 09:52:05 PST 2010
On Tuesday, November 30, 2010 09:10:03 Sean Kelly wrote:
> Steven Schveighoffer Wrote:
> > On Tue, 30 Nov 2010 10:06:40 -0500, Don <nospam at nospam.com> wrote:
> > > What are the use cases for logical const? Are there any other important
> > > ones, apart from caching?
> >
> > Being able to associate data with an object/struct without owning the
> > data. Deep in this thread I give an example of having a widget who knows
> > its location and knows how to draw itself in that location. Such a
> > function cannot be marked const even though no widget data is changed,
> > since the draw function is not const. But the Widget doesn't own the
> > location, it's just referencing it.
>
> Hm... can a const object mutate globals?
Yes. All it means for a const function to be const is that its this
pointer/reference is const. If you don't want it to mess with globals, you need
to make it pure.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list