Re: Mutually recursive template expansion

2021-10-04 Thread Paul Backus via Digitalmars-d-learn
On Monday, 4 October 2021 at 11:38:04 UTC, bauss wrote: Actually it is covered by the spec. See: https://dlang.org/spec/expression.html#mixin_expressions It clearly says: ``` Each AssignExpression in the ArgumentList is evaluated at compile time ``` Which means that Br cannot be used in Ar

Re: Mutually recursive template expansion

2021-10-04 Thread bauss via Digitalmars-d-learn
On Friday, 1 October 2021 at 14:26:39 UTC, jfondren wrote: On Friday, 1 October 2021 at 14:03:06 UTC, Stephen wrote: This code should work should mutual recursion be supported. It still wouldn't work, because structs are value types and it's impossible to say how large either struct is: Err

Re: Mutually recursive template expansion

2021-10-02 Thread Imperatorn via Digitalmars-d-learn
On Friday, 1 October 2021 at 14:03:06 UTC, Stephen wrote: I've been trying out templates in more depth and one thing I was wondering was whether template expansions with circular dependencies might work. Here is an example that doesn't work: ```d mixin(A!()); mixin(B!()); void main() {} templ

Re: Mutually recursive template expansion

2021-10-02 Thread Basile B. via Digitalmars-d-learn
On Saturday, 2 October 2021 at 08:48:24 UTC, Stephen wrote: Is this by design? No but it's easily explainable. ## without mixins ```d struct Ar { Br b; ubyte a; } struct Br { ubyte b; } ``` `Ar` semantic starts, members are analyzed, that begins with the variable declaration `Br b`. `Br` ty

Re: Mutually recursive template expansion

2021-10-02 Thread Stephen via Digitalmars-d-learn
On Friday, 1 October 2021 at 14:26:39 UTC, jfondren wrote: On Friday, 1 October 2021 at 14:03:06 UTC, Stephen wrote: This code should work should mutual recursion be supported. It still wouldn't work, because structs are value types and it's impossible to say how large either struct is: Err

Re: Mutually recursive template expansion

2021-10-01 Thread jfondren via Digitalmars-d-learn
On Friday, 1 October 2021 at 14:03:06 UTC, Stephen wrote: This code should work should mutual recursion be supported. It still wouldn't work, because structs are value types and it's impossible to say how large either struct is: Error: struct `mutualrec.Ar` no size because of forward referen

Mutually recursive template expansion

2021-10-01 Thread Stephen via Digitalmars-d-learn
I've been trying out templates in more depth and one thing I was wondering was whether template expansions with circular dependencies might work. Here is an example that doesn't work: ```d mixin(A!()); mixin(B!()); void main() {} template A() { const char[] A = q{ struct Ar {

Re: Is this a compiler error? "recursive template expansion"

2020-12-08 Thread Nathan S. via Digitalmars-d-learn
On Tuesday, 8 December 2020 at 22:01:52 UTC, Basile B. wrote: On Tuesday, 8 December 2020 at 20:11:40 UTC, Nathan S. wrote: The following code fails to compile. Is this a compiler error or if not what is wrong with the code? What is wrong is that partial specialization is not correct. The corr

Re: Is this a compiler error? "recursive template expansion"

2020-12-08 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 8 December 2020 at 20:11:40 UTC, Nathan S. wrote: The following code fails to compile. Is this a compiler error or if not what is wrong with the code? What is wrong is that partial specialization is not correct. The correct partial specialization is: --- struct Template2(T) { e

Is this a compiler error? "recursive template expansion"

2020-12-08 Thread Nathan S. via Digitalmars-d-learn
following line is removed compilation succeeds // without any other changes. Template1!int x; } void main() { } --- Failure message: main.d(20): Error: struct main.Template1(Param1, Param2 = Template2!Param1) recursive template expansion main.d(20):while looking for match for

Re: Can this recursive template type with named type parameters be simplified or improved?

2018-10-21 Thread Hakan Aras via Digitalmars-d-learn
On Sunday, 21 October 2018 at 21:23:35 UTC, aliak wrote: Hi, I'm playing around with a recursive template type that allows for named template parameters. The problem is that it requires a lot of repetition and becomes more error prone as the number of named arguments increase. So 1

Can this recursive template type with named type parameters be simplified or improved?

2018-10-21 Thread aliak via Digitalmars-d-learn
Hi, I'm playing around with a recursive template type that allows for named template parameters. The problem is that it requires a lot of repetition and becomes more error prone as the number of named arguments increase. So 1) Any ideas on how to make it less error prone? less repetitio

Re: `recursive template expansion` error msg isn't informative

2018-05-08 Thread drug via Digitalmars-d-learn
07.05.2018 17:22, Timoses пишет: On Monday, 7 May 2018 at 10:28:14 UTC, drug wrote: I get the error like: ``` ./foo/bar/baz/builder.d(57,23): Error: template instance `staticMap!(DebugTypeMapper, BaseDebuggerTypes)` recursive template expansion ``` That's all. It doesn's print inst

Re: `recursive template expansion` error msg isn't informative

2018-05-07 Thread Timoses via Digitalmars-d-learn
On Monday, 7 May 2018 at 10:28:14 UTC, drug wrote: I get the error like: ``` ./foo/bar/baz/builder.d(57,23): Error: template instance `staticMap!(DebugTypeMapper, BaseDebuggerTypes)` recursive template expansion ``` That's all. It doesn's print instantiations stack so I can't

`recursive template expansion` error msg isn't informative

2018-05-07 Thread drug via Digitalmars-d-learn
I get the error like: ``` ./foo/bar/baz/builder.d(57,23): Error: template instance `staticMap!(DebugTypeMapper, BaseDebuggerTypes)` recursive template expansion ``` That's all. It doesn's print instantiations stack so I can't track back the reason. Could someone give an advice

Re: recursive template expansion: Why does this not compile?

2018-03-22 Thread Ontonator via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 23:05:22 UTC, Jonathan M Davis wrote: On Wednesday, March 21, 2018 22:50:32 Ontonator via Digitalmars-d-learn wrote: On Wednesday, 21 March 2018 at 06:39:22 UTC, ag0aep6g wrote: > On 03/21/2018 01:47 AM, Ontonator wrote: >> The following code does not compile: >>>

Re: recursive template expansion: Why does this not compile?

2018-03-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 21, 2018 22:50:32 Ontonator via Digitalmars-d-learn wrote: > On Wednesday, 21 March 2018 at 06:39:22 UTC, ag0aep6g wrote: > > On 03/21/2018 01:47 AM, Ontonator wrote: > >> The following code does not compile: > >>> [...] > >> > >> It gives the error: > >>> [...] > >> > >> The a

Re: recursive template expansion: Why does this not compile?

2018-03-21 Thread Ontonator via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 06:39:22 UTC, ag0aep6g wrote: On 03/21/2018 01:47 AM, Ontonator wrote: The following code does not compile: [...] It gives the error: [...] The aliases do not have to be aliases, as long as there is some reference to the class (e.g. method and variable decl

Re: recursive template expansion: Why does this not compile?

2018-03-20 Thread ag0aep6g via Digitalmars-d-learn
{} It gives the error: test.d(12): Error: class `test.TemplatedClass(T : SuperClass)` recursive template expansion test.d(12):    while looking for match for TemplatedClass!(C) The aliases do not have to be aliases, as long as there is some reference to the class (e.g. method and variable

Re: recursive template expansion: Why does this not compile?

2018-03-20 Thread Jonathan M Davis via Digitalmars-d-learn
lass { > > > > alias T = TemplatedClass!B; > > > > } > > > > class B : SuperClass { > > > > alias T = TemplatedClass!C; > > > > } > > > > class C : SuperClass {} > > It gives the error: > > test.d(12): Error

recursive template expansion: Why does this not compile?

2018-03-20 Thread Ontonator via Digitalmars-d-learn
: class `test.TemplatedClass(T : SuperClass)` recursive template expansion test.d(12):while looking for match for TemplatedClass!(C) The aliases do not have to be aliases, as long as there is some reference to the class (e.g. method and variable declarations also work). What exactly is

Re: Recursive template instantiation

2017-03-13 Thread ag0aep6g via Digitalmars-d-learn
On 03/13/2017 11:58 PM, Stefan Koch wrote: On Monday, 13 March 2017 at 22:05:24 UTC, Jack Applegame wrote: Is this a bug? No it's not struct C { B!C; } is an error. Howto compute C ? <--\ let's check the members; | The member needs a template. | Howto compute the template

Re: Recursive template instantiation

2017-03-13 Thread ag0aep6g via Digitalmars-d-learn
On 03/14/2017 12:02 AM, Stefan Koch wrote: On Monday, 13 March 2017 at 22:59:36 UTC, ag0aep6g wrote: [...] struct A(T) { void m() { char[T.sizeof] data; } } /* ... rest as above ... */ I don't see how the destructor makes a difference. Soo, bug? Try to use m. Work

Re: Recursive template instantiation

2017-03-13 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 13 March 2017 at 22:59:36 UTC, ag0aep6g wrote: On 03/13/2017 03:26 PM, Jack Applegame wrote: I'm pretty sure that this code should compile (https://dpaste.dzfl.pl/cf1e1ee6ef4b): struct A(T) { ~this() { char[T.sizeof] data; } } struct B(T) { A!T foo; } struct C {

Re: Recursive template instantiation

2017-03-13 Thread ag0aep6g via Digitalmars-d-learn
On 03/13/2017 03:26 PM, Jack Applegame wrote: I'm pretty sure that this code should compile (https://dpaste.dzfl.pl/cf1e1ee6ef4b): struct A(T) { ~this() { char[T.sizeof] data; } } struct B(T) { A!T foo; } struct C { B!C bar; } void main() { C c; } But it doesn't:

Re: Recursive template instantiation

2017-03-13 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 13 March 2017 at 22:05:24 UTC, Jack Applegame wrote: Is this a bug? No it's not struct C { B!C; } is an error. Howto compute C ? <--\ let's check the members; | The member needs a template. | Howto compute the template ? | let's compute the parameters. | What

Re: Recursive template instantiation

2017-03-13 Thread Jack Applegame via Digitalmars-d-learn
Is this a bug?

Recursive template instantiation

2017-03-13 Thread Jack Applegame via Digitalmars-d-learn
I'm pretty sure that this code should compile (https://dpaste.dzfl.pl/cf1e1ee6ef4b): struct A(T) { ~this() { char[T.sizeof] data; } } struct B(T) { A!T foo; } struct C { B!C bar; } void main() { C c; } But it doesn't: /d300/f416.d(3): Error: struct f416.C no size

Re: Recursive template

2014-11-15 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
Slightly simpler: struct SomeType(K, V) {} alias X(V) = V; alias X(V, K...) = SomeType!(K[0], X!(V, K[1 .. $])); That's a recurring pattern to get used to: aliasing away to one of the parameters in a terminal and/or degenerate case. Also: that an empty tuple matches no parameter "m

Re: Recursive template

2014-11-15 Thread Eric via Digitalmars-d-learn
Thanks! -Eric On Saturday, 15 November 2014 at 18:49:32 UTC, anonymous wrote: On Saturday, 15 November 2014 at 18:30:00 UTC, Eric wrote: Hi - I've never designed a recursive template before, but I think that would solve my problem. What I would like is someting like this: class X

Re: Recursive template

2014-11-15 Thread anonymous via Digitalmars-d-learn
On Saturday, 15 November 2014 at 18:30:00 UTC, Eric wrote: Hi - I've never designed a recursive template before, but I think that would solve my problem. What I would like is someting like this: class X(V, K...) { // I want to declare a type based on K and V such // that for X!(V

Recursive template

2014-11-15 Thread Eric via Digitalmars-d-learn
Hi - I've never designed a recursive template before, but I think that would solve my problem. What I would like is someting like this: class X(V, K...) { // I want to declare a type based on K and V such // that for X!(V, int, string, double) the resulting // declaration wou

Re: recursive template at ctfe

2013-11-26 Thread Shammah Chancellor
On 2013-11-26 21:31:55 +, bioinfornatics said: On Tuesday, 26 November 2013 at 21:18:29 UTC, Shammah Chancellor wrote: On 2013-11-26 21:00:56 +, bioinfornatics said: On Tuesday, 26 November 2013 at 20:50:13 UTC, bioinfornatics wrote: On Tuesday, 26 November 2013 at 20:29:00 UTC, bear

Re: recursive template at ctfe

2013-11-26 Thread bioinfornatics
On Tuesday, 26 November 2013 at 21:18:29 UTC, Shammah Chancellor wrote: On 2013-11-26 21:00:56 +, bioinfornatics said: On Tuesday, 26 November 2013 at 20:50:13 UTC, bioinfornatics wrote: On Tuesday, 26 November 2013 at 20:29:00 UTC, bearophile wrote: bioinfornatics: I wrote some template

Re: recursive template at ctfe

2013-11-26 Thread Shammah Chancellor
On 2013-11-26 21:00:56 +, bioinfornatics said: On Tuesday, 26 November 2013 at 20:50:13 UTC, bioinfornatics wrote: On Tuesday, 26 November 2013 at 20:29:00 UTC, bearophile wrote: bioinfornatics: I wrote some template to compute at compile time how many bits is need for a number x. http:/

Re: recursive template at ctfe

2013-11-26 Thread bioinfornatics
On Tuesday, 26 November 2013 at 20:50:13 UTC, bioinfornatics wrote: On Tuesday, 26 November 2013 at 20:29:00 UTC, bearophile wrote: bioinfornatics: I wrote some template to compute at compile time how many bits is need for a number x. http://www.dpaste.dzfl.pl/99a842fd That works for small

Re: recursive template at ctfe

2013-11-26 Thread bioinfornatics
On Tuesday, 26 November 2013 at 20:29:00 UTC, bearophile wrote: bioinfornatics: I wrote some template to compute at compile time how many bits is need for a number x. http://www.dpaste.dzfl.pl/99a842fd That works for small number but after i got an error about limit recursion Instead of te

Re: recursive template at ctfe

2013-11-26 Thread bearophile
bioinfornatics: I wrote some template to compute at compile time how many bits is need for a number x. http://www.dpaste.dzfl.pl/99a842fd That works for small number but after i got an error about limit recursion Instead of template recursion, have you tried regular code run at compile tim

recursive template at ctfe

2013-11-26 Thread bioinfornatics
Hi, I wrote some template to compute at compile time how many bits is need for a number x. http://www.dpaste.dzfl.pl/99a842fd That works for small number but after i got an error about limit recursion how to work around this in my case ?

Re: How can i increase max number recursive template expansions?

2013-07-10 Thread Ellery Newcomer
On 07/07/2013 01:22 PM, John Colvin wrote: On Sunday, 7 July 2013 at 19:55:26 UTC, QAston wrote: I have a large enum in my code (opcodes for a protocol) - using std.traits.EnumMembers gives me a recursive template error. How can i increase max number recursive template expansions? I don&#

Re: How can i increase max number recursive template expansions?

2013-07-08 Thread Simen Kjaeraas
On 2013-07-08, 11:03, bearophile wrote: Simen Kjaeraas: However, you can amend std.traits.EnumMembers to work with larger enums by using this version: Worth putting in Phobos? Filed: http://d.puremagic.com/issues/show_bug.cgi?id=10569 And created a pull request: https://github.com/D-Pro

Re: How can i increase max number recursive template expansions?

2013-07-08 Thread John Colvin
On Monday, 8 July 2013 at 09:03:24 UTC, bearophile wrote: Simen Kjaeraas: However, you can amend std.traits.EnumMembers to work with larger enums by using this version: Worth putting in Phobos? Bye, bearophile I reckon so. It's rare to have such huge structs or classes that this sort of t

Re: How can i increase max number recursive template expansions?

2013-07-08 Thread bearophile
Simen Kjaeraas: However, you can amend std.traits.EnumMembers to work with larger enums by using this version: Worth putting in Phobos? Bye, bearophile

Re: How can i increase max number recursive template expansions?

2013-07-07 Thread QAston
On Sunday, 7 July 2013 at 20:28:12 UTC, John Colvin wrote: On Sunday, 7 July 2013 at 20:22:59 UTC, Simen Kjaeraas wrote: On 2013-07-07, 21:55, QAston wrote: I have a large enum in my code (opcodes for a protocol) - using std.traits.EnumMembers gives me a recursive template error. How can i

Re: How can i increase max number recursive template expansions?

2013-07-07 Thread John Colvin
On Sunday, 7 July 2013 at 20:41:17 UTC, Simen Kjaeraas wrote: On 2013-07-07, 22:28, John Colvin wrote: We came up with almost identical solutions, posted within 19 seconds of each other! Sorta. Mine does repeated halving, and makes DMD run out of memory with 16384 enum members. Yours balks a

Re: How can i increase max number recursive template expansions?

2013-07-07 Thread Simen Kjaeraas
On 2013-07-07, 22:28, John Colvin wrote: We came up with almost identical solutions, posted within 19 seconds of each other! Sorta. Mine does repeated halving, and makes DMD run out of memory with 16384 enum members. Yours balks at an enum of > about 1000 elements. -- Simen

Re: How can i increase max number recursive template expansions?

2013-07-07 Thread John Colvin
On Sunday, 7 July 2013 at 20:22:59 UTC, Simen Kjaeraas wrote: On 2013-07-07, 21:55, QAston wrote: I have a large enum in my code (opcodes for a protocol) - using std.traits.EnumMembers gives me a recursive template error. How can i increase max number recursive template expansions? You

Re: How can i increase max number recursive template expansions?

2013-07-07 Thread John Colvin
On Sunday, 7 July 2013 at 19:55:26 UTC, QAston wrote: I have a large enum in my code (opcodes for a protocol) - using std.traits.EnumMembers gives me a recursive template error. How can i increase max number recursive template expansions? I don't think you can. Please file a bug report:

Re: How can i increase max number recursive template expansions?

2013-07-07 Thread Simen Kjaeraas
On 2013-07-07, 21:55, QAston wrote: I have a large enum in my code (opcodes for a protocol) - using std.traits.EnumMembers gives me a recursive template error. How can i increase max number recursive template expansions? You can't. However, you can amend std.traits.EnumMembers to work

How can i increase max number recursive template expansions?

2013-07-07 Thread QAston
I have a large enum in my code (opcodes for a protocol) - using std.traits.EnumMembers gives me a recursive template error. How can i increase max number recursive template expansions?