digitalmars.D.bugs - [Issue 10812] New: Improve Template Pattern Matching
- d-bugmail puremagic.com (41/41) Aug 12 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10812
- d-bugmail puremagic.com (20/20) Aug 12 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10812
- d-bugmail puremagic.com (9/9) Aug 12 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10812
http://d.puremagic.com/issues/show_bug.cgi?id=10812
Summary: Improve Template Pattern Matching
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: monkeyworks12 hotmail.com
import std.typecons;
template Pair(T, U)
{
alias Pair = Tuple!(T, U);
}
T left(T, U)(Pair!(T, U) t)
{
return t[0];
}
void main()
{
//Error: template left(T, U)(Pair!(T, U) t) cannot deduce
//template function from argument types !()(Tuple!(int, string))
auto t = Pair!(int, string)(0, "");
assert(left(t) == 0);
}
This is really annoying, and it's going to get even worse when the new alias(T)
syntax is introduced. I know that aliases are expanded before other stuff, but
using `typedef Tuple!(T, U) Pair` instead gives the same error message.
*Ideally*, I could also do something like this (this currently doesn't
compile):
T left(T, U, Tup: Pair!(T, U))(Tup t)
{
return t[0];
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 12 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10812
It looks like there is a way to "work around" this:
import std.typecons;
alias Pair = Tuple;
T left(T, U)(Pair!(T, U) t)
{
return t[0];
}
void main()
{
//Ok
auto t = Pair!(int, string)(0, "");
assert(left(t) == 0);
}
I can't think of a different use-case at the moment that this doesn't cover, so
I'll close this for the time being.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 12 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10812
monkeyworks12 hotmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |LATER
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 12 2013









d-bugmail puremagic.com 