www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3881] New: Structs as template arguments

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

           Summary: Structs as template arguments
           Product: D
           Version: 2.040
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2010-03-05 08:17:47 PST ---
The following D2 program produces the error:
test.d(4): Error: arithmetic/string type expected for value-parameter, not Foo


struct S { int x; }

// template IncS(alias f) { // works
template IncS(S f) {        // doesn't work
    enum S IncS = S(f.x + 1);
}

void main() {
    enum S f1 = S(1);
    enum S f2 = IncS!(f1);
}


It works replacing IncS(S f) with IncS(alias f), but I think using the struct
name is more type safe (there 'alias' is like dynamic typing at compile-time).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 05 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3881



--- Comment #1 from bearophile_hugs eml.cc 2010-03-05 08:36:29 PST ---
Created an attachment (id=582)
A possible example

This attach shows a small program (that computes the N Queens at compile time)
that I think may show the consequence of not being able to pass a struct to a
template. I am not sure that's the cause.

At the top of the program there is a constant named 'Bug', that is currently
false. If you set it to true the program prints the wrong value 0 instead of
92.

If the cause of the problem is not the alias of the Mark template, then I think
it can be a compiler bug (or maybe just a bug of the code that I don't
understand).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 05 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3881


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au


--- Comment #2 from Don <clugdbug yahoo.com.au> 2010-07-30 01:43:27 PDT ---
This seems to be a request to allow structs as template value parameters.
That's a major feature request. I suspect (haven't checked) that the test case
is an unrelated compiler bug.

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