Is this a bug in std.typecons.Tuple.slice?

Saurabh Das via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 4 21:31:15 PST 2016


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?



More information about the Digitalmars-d-learn mailing list