2013/3/29 Andrej Mitrovic <andrej.mitrovich@gmail.com>
I can agree that $identifier looks weird, but a feature to do it is*necessary*.
When you create a pattern for matching, there is two cases.
- All value part can be represented by literal.
- Some values would be made in runtime.
bool testMatch(T)(int first_value, T tup) {
if (auto {first_value, ...} = tup) { return true; } else { return false; }
// first_value should be replaced to the given function argument, rather than capturing tup[0]
}
assert(testMatch(1, {1, 2, 3}) == true);
assert(testMatch(2, {1, 2, 3}) == false);
To distinct the capturing and evaluated value, var and $var is necessary.
Syntax for the feature is still debatable.