Thread overview
Const question
Mar 23, 2008
Graham St Jack
Mar 24, 2008
Craig Black
Mar 24, 2008
Graham St Jack
Mar 24, 2008
Walter Bright
Mar 24, 2008
Graham St Jack
Mar 28, 2008
Walter Bright
Mar 31, 2008
Graham St Jack
Mar 24, 2008
Janice Caron
Mar 24, 2008
Simen Kjaeraas
March 23, 2008
I have finally taken the plunge and moved over to D 2.x.

The experience is good so far except for a few problems with const (I want const btw), the biggest of which is the tail-const issue for classes, which is still an active area of discussion.

My question is more mundane - are there plans to fix the const- correctness of things in the language and phobos, specifically things like opCmp, opAdd, etc? I find I am having to cast away const in order to use overloaded operators, which is very annoying.
March 24, 2008
"Graham St Jack" <grahams@acres.com.au> wrote in message news:fs6mtj$1muc$1@digitalmars.com...
>I have finally taken the plunge and moved over to D 2.x.
>
> The experience is good so far except for a few problems with const (I
> want const btw), the biggest of which is the tail-const issue for
> classes, which is still an active area of discussion.

This is still being discussed?  Is Walter considering a fix for it?

-Craig 

March 24, 2008
On Sun, 23 Mar 2008 20:46:43 -0500, Craig Black wrote:

> "Graham St Jack" <grahams@acres.com.au> wrote in message news:fs6mtj$1muc$1@digitalmars.com...
>>I have finally taken the plunge and moved over to D 2.x.
>>
>> The experience is good so far except for a few problems with const (I want const btw), the biggest of which is the tail-const issue for classes, which is still an active area of discussion.
> 
> This is still being discussed?  Is Walter considering a fix for it?
> 
> -Craig

The discussion is under "const debacle", posted on 19th March. It looks like plenty more thinking is needed to sort it out.
March 24, 2008
Graham St Jack wrote:
> The discussion is under "const debacle", posted on 19th March. It looks like plenty more thinking is needed to sort it out.

The const debacle thing is something else.
March 24, 2008
On 24/03/2008, Craig Black <craigblack2@cox.net> wrote:
>
> This is still being discussed?  Is Walter considering a fix for it?

Not Walter, Andrei. Andrei has a template solution, Rebindable!(). Unfortunately, right now it's undocumented and shouldn't be used because it will likely change as D2 changes. I think Andrei is waiting for D to support opImplicitCast. I think, once we have that, his template will work as you'd expect.

This is discussed in the thread "Idea to ease tail-const class reference woes".
March 24, 2008
On Sun, 23 Mar 2008 22:36:08 -0700, Walter Bright wrote:

> Graham St Jack wrote:
>> The discussion is under "const debacle", posted on 19th March. It looks like plenty more thinking is needed to sort it out.
> 
> The const debacle thing is something else.

Oops.

While I have your attention, what is the plan for expressing that an object is const or immutable and to have a mutable reference to it? Arrays are fine (like "string"), but what is the deal for classes?
March 24, 2008
On Sun, 23 Mar 2008 23:51:31 +0100, Graham St Jack <grahams@acres.com.au> wrote:

> I have finally taken the plunge and moved over to D 2.x.
>
> The experience is good so far except for a few problems with const (I
> want const btw), the biggest of which is the tail-const issue for
> classes, which is still an active area of discussion.
>
> My question is more mundane - are there plans to fix the const-
> correctness of things in the language and phobos, specifically things
> like opCmp, opAdd, etc? I find I am having to cast away const in order to
> use overloaded operators, which is very annoying.


opAdd and friends are easy to fix in most situations:

    const Foo opAdd(const Foo rhs)

Of course, if this pattern is not used in the std lib, that is Walter's (and others') job.

-- Simen
March 28, 2008
Graham St Jack wrote:
> While I have your attention, what is the plan for expressing that an object is const or immutable and to have a mutable reference to it? Arrays are fine (like "string"), but what is the deal for classes?

There is no plan to have a mutable reference to const class contents. It just doesn't work in the type system.
March 31, 2008
On Thu, 27 Mar 2008 23:05:03 -0700, Walter Bright wrote:

> Graham St Jack wrote:
>> While I have your attention, what is the plan for expressing that an object is const or immutable and to have a mutable reference to it? Arrays are fine (like "string"), but what is the deal for classes?
> 
> There is no plan to have a mutable reference to const class contents. It just doesn't work in the type system.

Ok, I can live with that. Thanks for the clarification.