According to D spec,
    structs, unions are value types.
    classes are ref types.

But this world is not perfectly described by the above 2. There are 4 cases:

  1. Value storage class inside value type.
      class C {};
      struct S {};

      struct Outer
      {
C cc; // ref storage for ref type. This is the rescue for splitting copy problem. D language's creators wanted this behavior. If
         S ss; // value storage for value type. OK.

         void funcC(C c) {} // ref param. Correction for splitting copy.
         void funcS(S s) {} // value param. OK.
      }

  2. Value storage class inside ref type.
      class Outer
      {
         C cc; // ref storage. Correction for splitting copy.
         S ss; // value storage. OK.

         void funcC(C c) {} // ref param. Correction for splitting copy.
         void funcS(S s) {} // value param. OK.
      }

  3. Ref storage class inside a ref type.
      class Outer
      {
         C cc; // ref storage for ref type. OK.
         S ss; // How? Wanted ref, but value storage here

         void funcC(C c) {} // ref param. OK.
         void funcS(ref S s) {} // ref param for value type. OK.
      }

  4. Ref storage class inside value type.
      struct Outer
      {
         C c; // ref storage for ref type. OK.
         S s; // How? Wanted ref, but value storage here

         void funcC(C c) {} // ref param. OK.
         void funcS(ref S s) {} // ref param for value type. OK.
      }

I can solve case 3+4 by wrapping struct S inside a class template. But can we have a nicer / straightforward syntax? Is there any problem that prevent ref storage class declaration for struct types, sir?

Reply via email to