Bug 6394 – template type constraints embedded in the function parameters.
Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-07-28T08:43:00Z
Last change time
2014-03-19T19:13:36Z
Assigned to
nobody
Creator
gor
Comments
Comment #0 by gor — 2011-07-28T08:43:43Z
Comment #1 by gor — 2011-07-28T08:49:18Z
Given the code:
---------------
template SomeStruct(Type)
{
static if(is(Type == struct) || is(Type == class) || is(Type == interface))
enum StaticStruct = true;
else
enum StaticStruct = false;
}
---------------
I suggest a syntax sugar for template functions:
---------------
void f(SomeStruct s)
{
}
---------------
be transformed into:
---------------
void f(Type_0_)(Type_0_ s)
if(SomeStruct!Type_0_)
{
}
---------------
IF the given type isn't a valid type, it'll search for a template, that takes a single type and evaluates to a bool and transform the function if the type name is such a template.
this would greatly increase the readability of generic functions and allow to avoid creating enormous template constraints, as well as provide a better diagnostics, like "the type T is not a SomeStruct" or something like that.
Comment #2 by lt.infiltrator — 2014-03-19T19:13:36Z