Tuple.rename

* Overload of _rename that takes an associative array * translate as a template parameter, where the keys are * either the names or indices of the members to be changed * and the new names are the corresponding values. * Every key in translate must be the name of a member of the * tuple. * The same rules for empty strings apply as for the variadic * template overload of _rename.

  1. ref rename()
  2. ref rename()
    struct Tuple
    ref inout
    rename
    (
    alias translate
    )
    ()
    if (
    is(typeof(translate) : V[K],
    V
    K
    ) &&
    &&
    (
    is(K : size_t)
    )
    )

Examples

1 //replacing names by their current name
2 
3 Tuple!(float, "dat", size_t[2], "pos") t1;
4 t1.pos = [2, 1];
5 auto t1Named = t1.rename!(["dat": "height"]);
6 t1Named.height = 3.4;
7 assert(t1Named.pos == [2, 1]);
8 t1Named.rename!(["height": "altitude"]).altitude = 5;
9 assert(t1Named.height == 5);
10 
11 Tuple!(int, "a", int, "b") t2;
12 t2 = tuple(3, 4);
13 auto t2Named = t2.rename!(["a": "b", "b": "c"]);
14 assert(t2Named.b == 3);
15 assert(t2Named.c == 4);
16 
17 const t3 = Tuple!(int, "a", int, "b")(3, 4);
18 const t3Named = t3.rename!(["a": "b", "b": "c"]);
19 assert(t3Named.b == 3);
20 assert(t3Named.c == 4);
1 //replace names by their position
2 
3 Tuple!(float, "dat", size_t[2], "pos") t1;
4 t1.pos = [2, 1];
5 auto t1Named = t1.rename!([0: "height"]);
6 t1Named.height = 3.4;
7 assert(t1Named.pos == [2, 1]);
8 t1Named.rename!([0: "altitude"]).altitude = 5;
9 assert(t1Named.height == 5);
10 
11 Tuple!(int, "a", int, "b", int, "c") t2;
12 t2 = tuple(3, 4, 5);
13 auto t2Named = t2.rename!([0: "c", 2: "a"]);
14 assert(t2Named.a == 5);
15 assert(t2Named.b == 4);
16 assert(t2Named.c == 3);

Meta

Suggestion Box / Bug Report