Const template

Bruno Medeiros brunodomedeiros+spam at com.gmail
Tue Jan 23 06:55:05 PST 2007


Lionello Lunesu wrote:
> Bruno Medeiros wrote:
>> Andrei Alexandrescu (See Website For Email) wrote:
>>> Frits van Bommel wrote:
>>>> You didn't respond to my paragraph on classes though:
>>>>
>>>> Frits van Bommel wrote:
>>>>  > I also don't see a way this can work for classes (in general). 
>>>> There's
>>>>  > no way to limit a non-final method to non-mutating operations 
>>>> that I'm
>>>>  > aware of, so it could easily be circumvented by subclassing. Even 
>>>> though
>>>>  > that would only allow direct access to non-private fields, 
>>>> mutating base
>>>>  > class methods could still be called for the rest (if available). 
>>>> So then
>>>>  > the only way to get a const version of a class would be if the class
>>>>  > doesn't allow mutations anyway (like java's String). Which leaves us
>>>>  > right back where we started :(.
>>>>  >
>>>>  > And I don't think a 'const' implementation should work for 
>>>> structs and
>>>>  > not for classes...
>>>
>>> I did when I wrote:
>>>
>>>  >> That is correct. Interface functions, nonfinal methods, and
>>>  >> declared-only functions must be annotated manually.
>>>
>>> I meant - yes, you are right.
>>>
>>> Today, Walter and myself have come with a semantics for const (as in, 
>>> "read-only view" that) seems to be a good starting point. The details 
>>> are yet to be ironed out, but here's the basic plot:
>>>
>>
>> So the keyword for the "read-only view" will be 'const' too? It will 
>> share space with the 'const' as in "compile time constant" ?
> 
> 'const' is not always a compile time constant. A const in function or in 
> a class can have a different value for each call/instance. Don't ask me 
> why.
> 
> 
> L.

I know that very well, I mentioned it ahead in the:
"So are we going to use the 'final' keyword for that? That's good since 
it clears up the overloaded meaning of 'const' in current D. (used both 
for compile time constants and final)"

Another post from some time ago about this:
http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=44168


-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list