Associative Array of Const Objects?

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 29 14:22:24 PDT 2015


On Sunday, 29 March 2015 at 20:29:50 UTC, bitwise wrote:
>> 3) It's not how C++ rolls.
>> `const Test test;` and `Test const test;` are equivalent in 
>> C++. You need that '*' in C++, too, to make a distinction 
>> between reference and data.
>
> I'm a little confused. I was comparing a C++ pointer-to-class 
> to a D reference, which are basically the same under the hood. 
> I wasn't trying to bring up C++ value types. I'm not sure how 
> they're relevant to the argument.

`Test` can be a pointer type:

class C {};
typedef C *Test;
const Test test1 = 0;
Test const test2 = 0; /* same type as test1 */

The point is that C++ shares the problem: If all you have is one 
identifier (and no pointer star), you can't distinguish the data 
from the pointer.

So C++ syntax could only be properly adopted into D, if D class 
references got something like the pointer star. At that point, 
current D syntax with parentheses would work, too.

>> 4) Rebindable works reasonably well, as far as I know.
>
> The verbosity and blatant disregard for DRY makes me CRY.
> See what I did there.. ;)
>
> Anyways, IMO, D could benefit from having "tailconst" but I 
> think it's a moot point.

Yeah, I don't like Rebindable very much either. But it works ok, 
so whatever. If you have strong arguments, maybe post to the 
general forum. For me it's just about aesthetics.


More information about the Digitalmars-d-learn mailing list