std.meta.Replace using index

Nicholas Wilson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 28 17:07:08 PDT 2017


On Friday, 28 July 2017 at 22:06:27 UTC, Ali Çehreli wrote:
> I think it works:
>
> template replace(T) {
>     template inside(Src...) {
>         template from(Dst...) {
>             import std.meta;
>             enum f = staticIndexOf!(T, Src);
>             static if (f == -1) {
>                 alias from = Src;
>             } else {
>                 alias from = AliasSeq!(Src[0 .. f], Dst[f], 
> inside!(Src[f + 1 .. $]).from!(Dst[f + 1 .. $]));
>             }
>         }
>     }
> }
>
> unittest {
>     import std.meta : AliasSeq;
>     replace!long
>         .inside!(long, int, long, long, float, long)
>         .from!(int, byte, char, double, dchar, real) a;
>     static assert(is (typeof(a) == AliasSeq!(int, int, char, 
> double, float, real)));
> }
>
> void main() {
> }
>
> Ali

Thanks!


More information about the Digitalmars-d-learn mailing list