Const sucks

Regan Heath regan at netmail.co.nz
Mon Sep 10 12:24:17 PDT 2007


Walter Bright wrote:
> o  tail const of a struct would have to be done by making the struct a 
> template:
> 
>   struct S(T) { T member; }
>   S!(int)   // tail mutable
>   S!(const(int)) // tail const

How is this going to work for a more complex struct?

struct Bar { int a; }
class Baz { int a; }
struct Foo
{
   int a;
   float b;
   char[] c;
   Bar d;
   Baz e;
}

> o  one can construct a template to generically produce tail const or 
> tail invariant versions of a type.

Including classes?  I saw no mention of how tail-const will be applied 
to classes, will they be handled in the same way as structs?

In general is this correct for a class reference:

class Baz { int a; }
const Baz b;  //neither b nor b.a can be changed

Regan



More information about the Digitalmars-d mailing list