[Issue 12411] New: New eponymous template syntax could support nested eponymous templates
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Mar 19 01:42:36 PDT 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12411
Summary: New eponymous template syntax could support nested
eponymous templates
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2014-03-19 01:42:34 PDT ---
Example code:
-----
import std.typetuple;
enum canAppend(R) = anySatisfy!(canAppendRange!R, Types);
private alias Types = TypeTuple!(int, float);
// problem: can't use new-style eponymous syntax for nexted templates
private template canAppendRange(R)
{
enum canAppendRange(T) = is(typeof({ R r = void; T t = void; r ~= t; }));
}
void main()
{
static assert(canAppend!(int[]));
static assert(canAppend!(float[]));
static assert(!canAppend!(byte[]));
}
-----
Notice how 'canAppendRange' has to use the old-style eponymous syntax in order
for it to be usable with partial instantiation in the call to anySatisfy.
Perhaps a somewhat reasonable enhancement would be to allow nested eponymous
syntax:
-----
enum canAppendRange(R)(T) = is(typeof({ R r = void; T t = void; r ~= t; }));
-----
A simplified example test-case:
-----
// old-style
template isEqual(T1)
{
template isEqual(T2)
{
enum bool isEqual = is(T1 == T2);
}
}
// new-style
enum isEqual(T1)(T2) = is(T1 == T2);
void main()
{
alias isInt = isEqual!int;
static assert(isInt!int);
}
-----
The whole idea is to allow new syntax to allow easier writing of templates
which can be partially instantiated.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list