[Issue 8713] New: Allow passing arguments to templates in CTFE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Sep 23 13:46:23 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8713

           Summary: Allow passing arguments to templates in CTFE
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: jens.k.mueller at gmx.de


--- Comment #0 from jens.k.mueller at gmx.de 2012-09-23 13:47:19 PDT ---
When doing CTFE it may be worthwhile to allow passing of function arguments to
template instantiations. This eases better integration between templates and
CTFE making meta programming more convenient.
Example:

bool foo(string a)                                                              
{                                                                               
    return bar!(a);                                                             
}                                                                               

template bar(string b)                                                          
{                                                                               
    enum bar = true;                                                            
}

fails to compile with
test.d(3): Error: variable a cannot be read at compile time

The problem is that foo must be compilable to be executed at run-time which
clearly cannot work with the above code. But if __ctfe was a compile-time known
value foo could be written like:
static if (__ctfe)
{
    return bar!(a)
}
else
{
    return false;
}

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


More information about the Digitalmars-d-bugs mailing list