The OpenD Programming Language

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

//replacing names by their current name

Tuple!(float, "dat", size_t[2], "pos") t1;
t1.pos = [2, 1];
auto t1Named = t1.rename!(["dat": "height"]);
t1Named.height = 3.4;
assert(t1Named.pos == [2, 1]);
t1Named.rename!(["height": "altitude"]).altitude = 5;
assert(t1Named.height == 5);

Tuple!(int, "a", int, "b") t2;
t2 = tuple(3, 4);
auto t2Named = t2.rename!(["a": "b", "b": "c"]);
assert(t2Named.b == 3);
assert(t2Named.c == 4);

const t3 = Tuple!(int, "a", int, "b")(3, 4);
const t3Named = t3.rename!(["a": "b", "b": "c"]);
assert(t3Named.b == 3);
assert(t3Named.c == 4);
//replace names by their position

Tuple!(float, "dat", size_t[2], "pos") t1;
t1.pos = [2, 1];
auto t1Named = t1.rename!([0: "height"]);
t1Named.height = 3.4;
assert(t1Named.pos == [2, 1]);
t1Named.rename!([0: "altitude"]).altitude = 5;
assert(t1Named.height == 5);

Tuple!(int, "a", int, "b", int, "c") t2;
t2 = tuple(3, 4, 5);
auto t2Named = t2.rename!([0: "c", 2: "a"]);
assert(t2Named.a == 5);
assert(t2Named.b == 4);
assert(t2Named.c == 3);

Meta