Thread overview
[Issue 1820] New: default template parameters cannot be omitted
Feb 07, 2008
d-bugmail
Jan 17, 2010
Don
Jul 03, 2011
yebblies
February 07, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1820

           Summary: default template parameters cannot be omitted
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: andrei@metalanguage.com


The following code compiles and runs as expected:

import std.stdio;

template wyda(string pred = ``)
{
    void wyda(int x) { writeln(pred, " ", x); }
}

void main()
{
    wyda(3);
    wyda!("a")(4);
}

However, the following equivalent code does not:

import std.stdio;

template wyda(string pred = ``)
{
    static if (true)
        void wyda(int x) { writeln(pred, " ", x); }
}

void main()
{
    wyda(3);
    wyda!("a")(4);
}

The proposed solution is to get rid to the maximum extent possible of the requirements for the noisy "!()" syntax. If a template name is specified without the "!", then it should simply assume "!()" followed.


Andrei


-- 

January 17, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=1820


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au
            Version|unspecified                 |1.00
           Severity|normal                      |enhancement


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 03, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=1820


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com


--- Comment #1 from yebblies <yebblies@gmail.com> 2011-07-03 14:28:33 EST ---
The issue here is in:

template func(T)
{
    static if (cond)
        void func(T x) {}
}

func is only a function template (onemember) when cond is true, and in the general case cond may rely on T, which relies on ifti.

The following might illustrate it better:

template func(T)
{
    static if (is(T == int)) // how could we know this before performing ifti?
        void func(T* x) {}
}

The compiler cannot generally evaluate static if conditions without the template args being known.  Although it could in very simple cases, I'm not sure it's worth the effort.

One place I think this could be done is inside VersionConditions.

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