www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - opDollar any

reply Joseph <JE342 gmail.com> writes:
Trying to do multi-dimension array but op-dollar doesn't seem to 
support arbitrary dimensions


 property int opDollar(size_t dim : k)() { return dims[k]; }
Sep 29 2017
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 09/29/2017 11:34 AM, Joseph wrote:
 Trying to do multi-dimension array but op-dollar doesn't seem to support 
 arbitrary dimensions
 
 
  property int opDollar(size_t dim : k)() { return dims[k]; }
 
 
It's called by multi-dimensional opIndex (or opSlice and perhaps others?; can be very complicated :) ). import std.stdio; struct S { property size_t opDollar(size_t dim)() { writefln("Called for dimension %s", dim); return dim; } auto opIndex(A...)(A args) { return 42; } } void main() { auto s = S(); s[$, $]; } Called for dimension 0 Called for dimension 1 Ali
Sep 29 2017