On Friday, 5 February 2016 at 05:18:01 UTC, Saurabh Das wrote:
[...]

Apologies for spamming. This is an improved implementation:

        @property
Tuple!(sliceSpecs!(from, to)) slice(size_t from, size_t to)() @safe const
        if (from <= to && to <= Types.length)
        {
            return typeof(return)(field[from .. to]);
        }

        ///
        unittest
        {
            Tuple!(int, string, float, double) a;
            a[1] = "abc";
            a[2] = 4.5;
            auto s = a.slice!(1, 3);
            static assert(is(typeof(s) == Tuple!(string, float)));
            assert(s[0] == "abc" && s[1] == 4.5);

            Tuple!(int, int, long) b;
            b[1] = 42;
            b[2] = 101;
            auto t = b.slice!(1, 3);
            static assert(is(typeof(t) == Tuple!(int, long)));
            assert(t[0] == 42 && t[1] == 101);
        }

These questions still remain:
1. Removing 'ref' from the return type
2. Adding 'const' to the function signature
3. Is the new implementation less efficient for correctly aligned tuples?
4. @trusted -> @safe?

Reply via email to