Extended Type Design.

Derek Parnell derek at nomail.afraid.org
Mon Mar 19 22:51:28 PDT 2007


On Mon, 19 Mar 2007 22:34:13 -0700, Andrei Alexandrescu (See Website For
Email) wrote:

> Tyler Knott wrote:
>> *const and invariant only make sense when applied to references, 
>> otherwise they are ignored or (preferably) errors.
> 
> Correct.

Can 'const' and 'invariant' apply to structs, especially ones that contain
references.

  struct Foo
  {
      char[] s;
      char c;
  }

  const Foo f;  // Is this a mistake then?
  f.s[0] = 'a'; // okay???
  f.s = "xyz";  // okay???
  f.s = "def".dup; // okay ???
  f.s.length = 1;  // okay?
  f.s ~= 'a'; // okay??
  f.c = 'a';   // okay???
  
  const Foo somefunc();
  f = somefunc; // okay??

  Foo someotherfunc();
  f = someotherfunc; // okay??

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
20/03/2007 4:45:27 PM



More information about the Digitalmars-d mailing list