template recursion
ag0aep6g
anonymous at example.com
Tue Jun 26 10:01:06 UTC 2018
On 06/26/2018 11:35 AM, Alex wrote:
> ´´´
> import std.range;
>
> void main()
> {
> T.member.tarr.length = 42;
> //put(T.member, 4); // line 6
> T.member.put(4); // line 7
> }
>
>
> struct T
> {
> void put(Type)(Type t){} // line 13
>
> static B member;
> }
>
> struct B
> {
> T[] tarr;
> void put(Type)(Type t)
> {
> put(tarr[t], t); // line 23
> }
> }
> ´´´
>
> Line 7 complains about:
> template app.B.put cannot deduce function from argument types !()(T, int)
>
> So, I see, that the compiler tries to use the same put function in line
> 23, as in line 7 and fails. Instead of this, I want to use the one in
> line 13.
> But I don't see any mistake at line 23...
On line 23, you're apparently trying to call std.range.put (which would
in turn call tarr[t].put). But being in a method that is itself called
"put", that line is instead interpreted as a recursive call (which
fails). To refer to std.range.put, you have to prepend a dot (the
"module scope operator"):
.put(tarr[t], t); // line 23
https://dlang.org/spec/module.html#module_scope_operators
More information about the Digitalmars-d-learn
mailing list