[Issue 1900] New: Template overload sets & traits templates
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Mar 9 01:24:29 PST 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1900
Summary: Template overload sets & traits templates
Product: D
Version: 2.012
Platform: PC
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: wbaxter at gmail.com
I'm not sure this kind of thing is supposed to work with template overload
sets, but I hope it is supposed to, as it is a pattern I see often in C++ code.
The idea is to define some "Traits" templates that define various compile-time
aspects of a particular type.
----
module main;
import std.stdio;
import A;
import B;
import generic;
void main()
{
AClass a;
BClass b;
writefln("Traits!(AClass).name: ", Traits!(AClass).name);
writefln("Traits!(BClass).name: ", Traits!(BClass).name);
writefln("Traits!(int).name: ", Traits!(int).name);
}
----
module A;
class AClass
{
}
template Traits(T : AClass)
{
enum string name = "AClass";
}
----
module B;
class BClass
{
}
string func(BClass b) {
return "BClass";
}
template Traits(T : BClass)
{
enum string name = "BClass";
}
----
module generic;
struct Traits(T)
{
const string name = "any";
}
----
Right now I get:
main.d(18): template instance Traits is not a template declaration, it is a
overloadset
main.d(18): Error: undefined identifier Traits!(AClass).name
(Also note the grammar error in the message "it is a overload set".)
--
More information about the Digitalmars-d-bugs
mailing list