On Monday, 29 July 2013 at 15:57:36 UTC, monarch_dodra wrote:
On Monday, 29 July 2013 at 15:31:39 UTC, bearophile wrote:
How do you tell apart values from not values? :-)
Is this brutal enough? :-)
enum SameKind(T...) =
__traits(compiles, {enum x = T[0], y = T[1]; }) ||
__traits(compiles, {alias x = T[0]; alias y = T[1]; });
template Select(bool condition, T...)
if (T.length == 2 && SameKind!T) {
static if (__traits(compiles, {enum x = T[0];})) {
static if (condition)
enum Select = T[0];
else
enum Select = T[1];
} else {
static if (condition)
alias Select = T[0];
else
alias Select = T[1];
}
}
void main() {
enum x = Select!(true, 10, 20);
static assert(x == 10);
int a = 1;
int b = 2;
alias y = Select!(true, a, b);
assert(y == 1);
alias T = Select!(true, int, long);
static assert(is(T == int));
}
Bye,
bearophile
But it's still "Select!(true, a, b)" and not "Select!(true, 1,
2)"...
Wait never mind my above post. Your approach works.