[Issue 1661] Not possible to specialize on template with integer	parameter
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Thu Feb 21 00:26:48 PST 2008
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=1661
wbaxter at gmail.com changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|DUPLICATE                   |
------- Comment #5 from wbaxter at gmail.com  2008-02-21 02:26 -------
I seem to have been wrong in using function templates.  C++ can't do that
either.  I think I must have thought it was simpler to demonstrate with
functions when I tried to distill a test case from the original C++ to D.  But
it does work with structs in C++, intractible or not.
Working C++ (save to specialize.cpp and compile with "dmc specialize.cpp"):
#include <stdio.h>
template <int N>
struct Number {
    static const int value = N;
};
template <typename T>
struct test_specialize 
{
    void talk() { printf("Not so special:\n"); }
};
template<int N>
struct test_specialize<Number<N> > 
{
    void talk() { printf("Ooh special - NUMBER N\n"); }
};
int main(int argc, char* argv[])
{
    test_specialize< Number<5> > x;
    x.talk();
    return 0;
}
-----
Not working D:
module specialize;
import std.stdio;
struct Number(int N) 
{
    const int value = N;
}
struct test_specialize(T)
{
    void talk() { writefln("Not so special:\n"); }
}
struct test_specialize(T : Number!(N))
{
    void talk() { writefln("Ooh special - NUMBER N\n"); }
}
int main()
{
    test_specialize!(Number!(5)) x;
    x.talk();
    return 0;
}
---
The C++ version outputs "ooh special", and the d version "Not so special".
-- 
    
    
More information about the Digitalmars-d-bugs
mailing list