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