std.meta.Replace using index

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 28 12:04:45 PDT 2017


On 07/28/2017 01:22 AM, Nicholas Wilson wrote:
> Hi
>
> I want to replace each occurrence of a particular type in an AliasSeq
> with a type from another AliasSeq (the both have the same length) with
> the corresponding index
>
> i.e. (int long long float) (byte char double dchar)  replacing long
> should yield (int char double float) std.meta.Replace would see to do
> the trick except the lambda depends in the index and I'm not sure how to
> pass that.

No time to complete it but here is a busy syntax that may work:

template Replace(T) {
     template From(Src...) {
         template With(Dst...) {
             pragma(msg, T);
             pragma(msg, Src);
             pragma(msg, Dst);

              // Place holder, which needs to be implemented. :)
             import std.meta : AliasSeq;
             alias With = AliasSeq!int;
         }
     }
}

void main() {
     Replace!long
         .From!(int, long, long, float)
         .With!(byte, char, double, dchar)  a;
}

Ali



More information about the Digitalmars-d-learn mailing list