www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2550] New: template specialization not working because of "static if"?

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2550

           Summary: template specialization not working because of "static
                    if"?
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: davidl 126.com


template pow10(long n)
{
        static if(n<0)
                const long pow10=0;
        else
                const long pow10=10*pow10!(n-1);
}

template pow10(long n:0)
{
        const long pow10=1;
}

static assert(pow10!(0) == 1);


-- 
Jan 01 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2550


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
            Summary|template specialization not |implicit conversions don't
                   |working because of "static  |apply to template value
                   |if"?                        |parameter specialization


--- Comment #1 from Don <clugdbug yahoo.com.au> 2009-09-24 07:15:54 PDT ---
Original title: 'template specialization not working because of "static if"?'

It's not because of 'static if'. This shows the same problem:

template pow10(long n){
   const long pow10=7;
}

template pow10(long n:0){
    const long pow10=1;
}

static assert(pow10!(0) == 1);

It will compile if you put
static assert(pow10!(0L) == 1);

It seems that the compiler requires template value specialisations have to
exactly match both type and value, but I don't see that in the spec anywhere.
Probably a bug. It's certainly pretty annoying.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 24 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2550



--- Comment #2 from Don <clugdbug yahoo.com.au> 2010-12-01 02:30:22 PST ---
I believe bug 2257 is the same issue.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 01 2010