CT-String as a Symbol

Vlad Levenfeld via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 21 00:46:02 PDT 2015


On Tuesday, 21 April 2015 at 07:01:27 UTC, Per Nordlöw wrote:
> On Tuesday, 21 April 2015 at 06:56:33 UTC, Per Nordlöw wrote:
>> On Monday, 20 April 2015 at 13:49:41 UTC, John Colvin wrote:
>>> On Thursday, 16 April 2015 at 18:12:35 UTC, Nordlöw wrote:
>>>> Is there a way to CT-query the arity of all opIndex and 
>>>> opSlice overloads?
>
> Further, this is slightly related to a way to query the 
> dimensions of a data-type. If possible I would like to have a 
> type trait for this. This type-trait could then be used both 
> for this challenge but also for figuring out how to create 
> randomized instances of multi-dimensional structures. This can 
> be used for automatic generation of data instances of 
> parameters in algorithm testing and benchmarking.

template dimensionality (S) {
   template count_dim (uint i = 0) {
     static if (is (typeof(S.init.opSlice!i (0,0))))
       enum count_dim = count_dim!(i+1);
     else enum count_dim = i;
   }

   alias dimensionality = count_dim!();
}

Then you throw in some more stuff to detect 1-dimensional cases.


More information about the Digitalmars-d-learn mailing list