D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7624 - std.typecons.Tuple slicing
Summary: std.typecons.Tuple slicing
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-01 15:37 UTC by bearophile_hugs
Modified: 2024-12-13 17:58 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012-03-01 15:37:08 UTC
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)?
Comment 1 dlangBugzillaToGithub 2024-12-13 17:58:52 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18422

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB