References in D

Mehrdad wfunction at hotmail.com
Tue Sep 25 02:01:28 PDT 2012


On Tuesday, 18 September 2012 at 19:30:24 UTC, Simen Kjaeraas 
wrote:
> On Tue, 18 Sep 2012 16:56:31 +0200, Mehrdad 
> <wfunction at hotmail.com> wrote:
>
>> On Saturday, 15 September 2012 at 23:28:36 UTC, Walter Bright 
>> wrote:
>>> I wouldn't worry about it. I suspect that most C++ 
>>> programmers think that references cannot be null.
>>
>>
>> Yeah, they can't be null _legally_.
>>
>> Kind of like how in D you can't strip away const _legally_.
>>
>> But the compiler doesn't complain if you don't obey the rules.
>
> Well, D at least makes you jump through hoops to strip away 
> const,


What does this have to do with const?



> while C++ assumes that however stupid the thing you seem to be 
> doing is, you probably intended to be that stupid.


Uhm, pardon? Not only is it irrelevant, it's also wrong:
It's harder to do that in C++ than in D.

In C++ you need const_cast (you shouldn't be using a C-style 
casts at all).

In D all you have is cast(), and it's damn easy to strip away 
const, especially when dealing with templates. And the compiler 
doesn't complain either!


More information about the Digitalmars-d mailing list