Bug 3881 – Structs as template arguments

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-03-05T08:17:00Z
Last change time
2014-10-02T12:11:39Z
Assigned to
nobody
Creator
bearophile_hugs

Attachments

IDFilenameSummaryContent-TypeSize
582bug3.dA possible exampleapplication/octet-stream2146

Comments

Comment #0 by bearophile_hugs — 2010-03-05T08:17:47Z
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).
Comment #1 by bearophile_hugs — 2010-03-05T08:36:29Z
Created attachment 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).
Comment #2 by clugdbug — 2010-07-30T01:43:27Z
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.
Comment #3 by k.hara.pg — 2014-10-02T12:11:39Z
Fixed in 2.066. *** This issue has been marked as a duplicate of issue 8848 ***