tuple parameter fwd

Artur Skawina art.08.09 at gmail.com
Mon Aug 5 12:49:43 PDT 2013


On 08/05/13 20:45, kdmult wrote:
> Hi,
> 
> I would like to use a tuple template parameter in the default value of another template parameter in the same class declaration as follows.
> 
> class A(P...) {}
> 
> class B(R = A!P, P...) {}
> 
> P... should be rightmost, so how can I use it in the preceding parameter?

If you don't need to specify R explicitly just add an
   
    alias R = A!P;

inside B. Otherwise, you'll have to manually determine whether
R was given - it's not possible to automatically tell if the
first B parm is: a) R, or b) the first element of P. For example:
 
   class B(_P...) {
      static if (is(_P[0] _ == A!TP, TP...)) {
         alias R = _P[0];
         alias P = _P[1..$];
      }
      else {
         alias R = A!P;
         alias P = _P;
      }
      //...
   }

artur


More information about the Digitalmars-d-learn mailing list