Using memberspaces for a property-like syntax and more

TommiT tommitissari at hotmail.com
Sat Feb 2 01:14:29 PST 2013


I propose we just forget about the whole concept of a property, 
and instead add to D a new construct called 'memberspace'. 
Memberspace subdivides the 'space' in which the member functions 
and operators of a type live into separately named 'subspaces', 
like namespaces do for freestanding functions and classes in C++. 
Read more about the uses of this idea over there (it's not my 
idea):

http://accu.org/index.php/journals/1527

Here's how it could look like:

struct S
{
     int _value;

     memberspace space1
     {
         int opCall() const
         {
             return _value;
         }

         void opAssign(int v)
         {
             _value = v;
         }

         void method() const { }
     }

     memberspace space2
     {
         static int opCall()
         {
             return 123;
         }
     }
}

void main()
{
     S var;
     var.space1 = 42;
     assert(var.space1() == 42);
     assert(S.space2() == 123);
     var.space1.method();

     int n1 = var.space1; // error
     int n2 = S.space2;   // error
}

Now, imagine replacing the name of your memberspace with the name 
of the thing you used to call a 'property'.


More information about the Digitalmars-d mailing list