Bug 9839 – std.traits.Select should be able to select symbols

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-30T13:05:00Z
Last change time
2013-03-31T05:59:12Z
Keywords
pull
Assigned to
andrej.mitrovich
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-03-30T13:05:07Z
Currently Select can't be used with variable names: import std.traits: Select; void main() { uint[] a1; ulong[] a2; alias T = int; alias T1 = Select!(T.sizeof == uint.sizeof, uint, ulong); alias a = Select!(is(T1 == uint), a1, a2); } DMD 2.063alpha: temp.d(7): Error: template instance Select!(true, a1, a2) Select!(true, a1, a2) does not match template declaration Select(bool condition, T, F) So I suggest to add an alias version of Select (in future when built-in types will become alias-able, the Select without alias will be removed): template Select(bool b, alias A1, alias A2) { static if (b) alias Select = A1; else alias Select = A2; } template Select(bool b, T1, T2) { static if (b) alias Select = T1; else alias Select = T2; } void main() { uint[] a1; ulong[] a2; alias T = int; alias T1 = Select!(T.sizeof == uint.sizeof, uint, ulong); alias a = Select!(is(T1 == uint), a1, a2); }
Comment #1 by andrej.mitrovich — 2013-03-31T04:06:46Z
Comment #2 by github-bugzilla — 2013-03-31T05:58:56Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/320b73a39d3950651c034a142b70d93b36a9ecb1 Fixes Issue 9839 - Select should be able to select symbols. https://github.com/D-Programming-Language/phobos/commit/39dd56dc551248917c093838ab43fdaf34a5501d Merge pull request #1235 from AndrejMitrovic/Fix9839 Issue 9839 - Select should be able to select symbols.