digitalmars.D.learn - having a trivial anonymous function call in template prevents
- Cauterite (15/15) Aug 17 2016 // ------ Example: ----------
- Adam D. Ruppe (5/8) Aug 17 2016 Function pointers and delegates are not valid compile time
- Cauterite (5/7) Aug 17 2016 I think you missed the point; it works perfectly fine without
- Lodovico Giaretta (4/12) Aug 17 2016 I think he meant that ({ return 0;})() cannot be executed at
- Steven Schveighoffer (4/14) Aug 17 2016 Yes, it can: https://dpaste.dzfl.pl/fca15065a4cf
- Cauterite (4/5) Aug 17 2016 Thanks, I've filed it. Just wanted to get a second opinion before
// ------ Example: ---------- template A(alias Arg) { enum A = Arg; enum Unrelated = ({return 0;})(); // this line prevent compilation }; void main() { enum FnPtr = &asdf; enum _ = A!FnPtr; }; void asdf() {}; // ( https://dpaste.dzfl.pl/79301f12e5fc ) Just by having a random `({return 0;})()` in the template body, suddenly the template rejects its arguments. I'm so confused, is this a bug? Or am I missing something?
Aug 17 2016
On Wednesday, 17 August 2016 at 13:09:40 UTC, Cauterite wrote:Just by having a random `({return 0;})()` in the template body, suddenly the template rejects its arguments. I'm so confused, is this a bug? Or am I missing something?Function pointers and delegates are not valid compile time variables. Best you can do is use them in an alias argument directly, but you cannot use them in an enum argument.
Aug 17 2016
On Wednesday, 17 August 2016 at 13:18:06 UTC, Adam D. Ruppe wrote:Best you can do is use them in an alias argument directly, but you cannot use them in an enum argument.I think you missed the point; it works perfectly fine without having this `({return 0;})()` in the template body (which, as far as I can see, doesn't appear to interact at all with the template argument).
Aug 17 2016
On Wednesday, 17 August 2016 at 13:21:16 UTC, Cauterite wrote:On Wednesday, 17 August 2016 at 13:18:06 UTC, Adam D. Ruppe wrote:I think he meant that ({ return 0;})() cannot be executed at compile time and assigned to an enum. That's why the instantiation is failing.Best you can do is use them in an alias argument directly, but you cannot use them in an enum argument.I think you missed the point; it works perfectly fine without having this `({return 0;})()` in the template body (which, as far as I can see, doesn't appear to interact at all with the template argument).
Aug 17 2016
On 8/17/16 9:23 AM, Lodovico Giaretta wrote:On Wednesday, 17 August 2016 at 13:21:16 UTC, Cauterite wrote:Yes, it can: https://dpaste.dzfl.pl/fca15065a4cf I think the OP's case is a bug. Please file. -SteveOn Wednesday, 17 August 2016 at 13:18:06 UTC, Adam D. Ruppe wrote:I think he meant that ({ return 0;})() cannot be executed at compile time and assigned to an enum. That's why the instantiation is failing.Best you can do is use them in an alias argument directly, but you cannot use them in an enum argument.I think you missed the point; it works perfectly fine without having this `({return 0;})()` in the template body (which, as far as I can see, doesn't appear to interact at all with the template argument).
Aug 17 2016
On Wednesday, 17 August 2016 at 13:33:26 UTC, Steven Schveighoffer wrote:I think the OP's case is a bug. Please file.Thanks, I've filed it. Just wanted to get a second opinion before concluding that it's a bug.
Aug 17 2016