digitalmars.D.learn - Error: cannot uniquely infer foreach argument types
- Agustin (24/24) Jun 14 2013 Hello, i'm trying to create a library with utilities classes like
- bearophile (13/16) Jun 14 2013 Maybe your code has multiple problems. If you want a precise
- Agustin (3/19) Jun 14 2013 int opApply(int delegate(ref int, ref E) delegation);
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/7) Jun 14 2013 I have just completed the translation of the "foreach with Structs and
- Steven Schveighoffer (7/14) Jun 14 2013 Here is the issue (as bearophile explained)
Hello, i'm trying to create a library with utilities classes like containers using Java API. Could anyone help me? public interface Iterator(E) { bool hasNext(); E next(); void remove(); int opApply(int delegate(ref E) delegation); } public class AbstractCollection(E) : Collection!E { ..... E[] toArray(E[] dst = null) { size_t count = size(); if( dst.length < count ) { dst.length = count; } Iterator!E it = iterator(); foreach(int i,E e; it) { -> Error: cannot uniquely infer foreach argument types dst[i] = e; } return dst[0 .. count]; } ..... }
Jun 14 2013
Agustin:Hello, i'm trying to create a library with utilities classes like containers using Java API.The problem with this is that most Phobos works with ranges...Could anyone help me?Maybe your code has multiple problems. If you want a precise answer, then give a complete little program. But a possible problem is in the opApply: int opApply(int delegate(ref E) delegation); If you want to use: foreach (i, e; it) { Then you need to put both in the opApply (or add a second opApply overload), something like: int opApply(int delegate(ref int, ref E) delegation); Bye, bearophile
Jun 14 2013
On Friday, 14 June 2013 at 17:17:46 UTC, bearophile wrote:Agustin:int opApply(int delegate(ref int, ref E) delegation); Works!, thanks.Hello, i'm trying to create a library with utilities classes like containers using Java API.The problem with this is that most Phobos works with ranges...Could anyone help me?Maybe your code has multiple problems. If you want a precise answer, then give a complete little program. But a possible problem is in the opApply: int opApply(int delegate(ref E) delegation); If you want to use: foreach (i, e; it) { Then you need to put both in the opApply (or add a second opApply overload), something like: int opApply(int delegate(ref int, ref E) delegation); Bye, bearophile
Jun 14 2013
On 06/14/2013 10:25 AM, Agustin wrote:int opApply(int delegate(ref int, ref E) delegation); Works!, thanks.I have just completed the translation of the "foreach with Structs and Classes" chapter: http://ddili.org/ders/d.en/foreach_opapply.html Ali
Jun 14 2013
On Fri, 14 Jun 2013 13:13:06 -0400, Agustin <agustin.l.alvarez hotmail.com> wrote:Hello, i'm trying to create a library with utilities classes like containers using Java API. Could anyone help me? public interface Iterator(E) { bool hasNext(); E next(); void remove();Here is the issue (as bearophile explained)int opApply(int delegate(ref E) delegation);Also, you may want to try an already-created library that's similar to Java in some respects: http://schveiguy.github.io/dcollections/ -Steve
Jun 14 2013