Static indexing
    JG 
    someone at somewhere.com
       
    Wed Jan 12 08:59:58 UTC 2022
    
    
  
Hi,
I want to make a type which has two fields x and y but can
also be indexed with [0] and [1] checked at compile time.
Is the following reasonable / correct?
     struct Point
     {
       double x;
       double y;
       alias expand = typeof(this).tupleof;
       alias expand this;
     }
     unittest
     {
       Point p = Point(1.2,3.4);
       assert(p[0]==1.2);
       assert(p[1]==3.4);
       assert(!__traits(compiles,Point.init[3]));
     }
    
    
More information about the Digitalmars-d-learn
mailing list