Bug 21011 – Variant and tuples by index

Status
NEW
Severity
minor
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-07-04T12:32:11Z
Last change time
2024-12-01T16:37:15Z
Assigned to
No Owner
Creator
superDIMMaX
Moved to GitHub: phobos#10429 →

Comments

Comment #0 by v.leolui — 2020-07-04T12:32:11Z
Test case: ---------------- Variant test = tuple(1,2); writeln(test[0]); ---------------- errors: ---------------- std.variant.VariantException@std\variant.d(1715): Variant: attempting to use incompatible types std.typecons.Tuple!(int, int).Tuple and int ---------------- 0x000000013F1292DB in std.variant.VariantN`20LU.VariantN.handler!(std.typecons.Tuple!(int, int)).handler at C:\D\dmd2\windows\bin\..\..\src\phobos\std\variant.d(475) 0x000000013F134536 in std.variant.VariantN`20LU.VariantN.opIndex!int.opIndex at C:\D\dmd2\windows\bin\..\..\src\phobos\std\variant.d(1113) ---------------- https://github.com/dlang/phobos/blob/master/std/variant.d#L475 access by index not working on tuples? but: writeln(test) - working;
Comment #1 by v.leolui — 2020-07-04T12:43:44Z
i found only one strange solution: writeln(test.get!(Tuple!(int, int))()[1]); and if this not issue, can be add ability opIndex and length on tuples?
Comment #2 by v.leolui — 2020-07-06T16:38:19Z
And i confused. why this not working with any [] opIndex API and(or) why not add tuples support? Variant know type Tuple!(int,int) and tuples have linear layout - union{Tuple!(int,int) t; int[2] a} work fine
Comment #3 by v.leolui — 2020-07-08T17:02:53Z
Found solution how avoid issue with Variant and access Tuple inside by [] - put tuple inside struct and -alias _tuple this- then -Variant v[0]- works and no errors.
Comment #4 by robert.schadek — 2024-12-01T16:37:15Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10429 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB