[Issue 1661] New: Not possible to specialize on template with integer parameter
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Nov 12 22:57:34 PST 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1661
Summary: Not possible to specialize on template with integer
parameter
Product: D
Version: 1.023
Platform: PC
OS/Version: Windows
Status: NEW
Severity: major
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: wbaxter at gmail.com
If you have a template that takes an integer parameter, there appears to be no
way to specialize on that integer.
Here are some examples of things that work and things that don't:
/*==========================================================================
* specialize.d
* Written in the D Programming Language (http://www.digitalmars.com/d)
*/
/***************************************************************************
* Test of specialization in D templates
*
* <TODO: Description>
*
* Author: William V. Baxter III
* Date: 13 Nov 2007
* License: Public Domain
*/
//===========================================================================
module specialize;
import std.stdio;
import std.string;
struct Container(Scalar,int N)
{
Scalar[N] values_;
}
template Container2(T) { alias Container!(T,2) Container2; }
struct Simple(T) {
T[] data;
}
struct Number(int N) {
const int value = N;
}
void test_specialize(T)() {
writefln("Not so special: ", typeid(T));
}
void test_specialize(T : float)() {
writefln("special - float");
}
void test_specialize(T : T[U], U)() {
writefln("special - Assoc Array of %s -> %s", typeid(U), typeid(T));
}
void test_specialize(T : Container!(T,3))() {
writefln("Ooh special - CONTAINER T,3");
}
void test_specialize(T : Simple!(T))() {
writefln("Ooh special - SIMPLE");
}
void test_specialize(T : Number!(2))() {
writefln("Ooh special - NUMBER = 2");
}
// Cases that don't match
// This doesn't compile
//void test_specialize(T : Number!(int N), int N)() {
// writefln("Ooh special - NUMBER");
//}
void test_specialize(T : Number!(N), int N)() {
writefln("Ooh special - NUMBER N");
}
void test_specialize(T : Container2!(T))() {
writefln("Ooh special - Container2!(T)");
}
void test_specialize(T : Container!(T,N), int N)() {
writefln("Ooh special - Container!(T,N)");
}
void main() {
test_specialize!(int)();
test_specialize!(float)();
test_specialize!(float[int])();
test_specialize!(Simple!(int))();
test_specialize!(Number!(2))();
test_specialize!(Container!(int,3))();
// These don't get matched
test_specialize!(Number!(5))();
test_specialize!(Container!(int,2))();
test_specialize!(Container!(int,4))();
}
--
More information about the Digitalmars-d-bugs
mailing list