Constant relationships between non-constant objects
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jun 19 08:16:43 PDT 2014
On Wed, 18 Jun 2014 01:40:47 -0400, Sebastian Unger
<sebunger44.remove at gmail.com> wrote:
> On Wednesday, 18 June 2014 at 04:38:25 UTC, Meta wrote:
>> On Wednesday, 18 June 2014 at 01:31:33 UTC, Sebastian Unger wrote:
>> There's no head const in D, but you can emulate it. This is a *very*
>> basic example that you can expand upon.
>>
>> http://dpaste.dzfl.pl/55cb22153fcc
>
> Thanks for that link. Yes, that is close. I'd even feel reasonaly well
> about it if it was in phobos so everybody can use the mechanism
> consistently.
>
> It does not however, quite meet the mark of "with ease". But it is
> possibly an acceptable hack around a shortcoming in the language.
> Comming from C++, it's not as though I'm not used to those. Just a shame
> to have to resort to it when D is so pretty close to getting rid of
> dirty hacks more or less completely.
It's not a dirty hack, it gives you exactly the control you desire. D has
extremely powerful mechanisms to make things that look like builtin
constructs, but are really library types. The given mechanism should
optimize down to direct assignments and reads via inlining.
I agree it should be in phobos. It just needs a template constraint to
make a non-reference type into a reference type, and it would be good to
go into std.typecons.
-Steve
More information about the Digitalmars-d
mailing list