[Issue 7624] New: std.typecons.Tuple slicing

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 1 15:37:09 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7624

           Summary: std.typecons.Tuple slicing
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2012-03-01 15:37:08 PST ---
std.typecons.Tuple supports both a "slice" method and normal array slicing
syntax:


import std.stdio, std.typecons;
void main() {
    Tuple!(int,float,string,ubyte) t4;
    t4[2] = "XXX";
    t4[3] = 99;
    writeln(t4);
    writeln(typeid(typeof(t4)), "\n");

    auto t2a = t4.slice!(1, 3);
    writeln(t2a);
    writeln(typeid(typeof(t2a)), "\n");

    auto t2b = t4[1 .. 3];
    writeln(t2b);
    writeln(typeid(typeof(t2b)), "\n");
}


Outout with DMD 2.059head:

Tuple!(int,float,string,ubyte)(0, nan, "XXX", 99)
std.typecons.Tuple!(int,float,string,ubyte).Tuple

Tuple!(float,string)(nan, "XXX")
std.typecons.Tuple!(float,string).Tuple

nanXXX
(float,immutable(char)[])


But the natural syntax, using [1..3], returns a typetuple. Having two different
kinds of tuples in a language is confusing, but slicing a kind tuple and see as
a result the other kind of tuple is a bit too much confusing.

Is it possible to modify D/Phobos to make  t4[1..3]   return a
std.typecons.Tuple (and then deprecate the "slice" method)?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list