Thread overview
Error instantiating std.container.Array
Mar 02, 2015
Tobias Pankrath
Mar 02, 2015
ketmar
Mar 02, 2015
Tobias Pankrath
Mar 02, 2015
Tobias Pankrath
Mar 02, 2015
Ali Çehreli
March 02, 2015
I'm trying to instantiate a std.container.Array of a given class (named Material), by a simple
Array!Material _myStuff;
I get two compile errors stating the following:

C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(85):
Error: template std.algorithm.initializeAll cannot deduce function from argument types !()(Material[]), candidates are:
  C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(1502):
    std.algorithm.initializeAll(Range)(Range range)
    if (isInputRange!Range
      && hasLvalueElements!Range
      && hasAssignableElements!Range)
  C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(1530):
    std.algorithm.initializeAll(Range)(Range range)
    if (is(Range == char[]) || is(Range == wchar[]))
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(825): Error: template std.algorithm.copy cannot deduce function from argument types !()(Range, Range), candidates are:
  C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(7808):
    std.algorithm.copy(Range1, Range2)(Range1 source, Range2 target)
    if (isInputRange!Range1 && isOutputRange!(Range2, ElementType!Range1))

Any idea about what might be happening? I can't give a quick minimal example of the code since it is quite complex (and I failed at using dustmite trying to minimize it)
March 02, 2015
On Monday, 2 March 2015 at 14:08:29 UTC, Francesco Cattoglio wrote:
> I'm trying to instantiate a std.container.Array of a given class (named Material), by a simple
> Array!Material _myStuff;
> I get two compile errors stating the following:
>
> C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(85):
> Error: template std.algorithm.initializeAll cannot deduce function from argument types !()(Material[]), candidates are:
>   C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(1502):
>     std.algorithm.initializeAll(Range)(Range range)
>     if (isInputRange!Range
>       && hasLvalueElements!Range
>       && hasAssignableElements!Range)
>   C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(1530):
>     std.algorithm.initializeAll(Range)(Range range)
>     if (is(Range == char[]) || is(Range == wchar[]))
> C:\D\dmd2\windows\bin\..\..\src\phobos\std\container\array.d(825): Error: template std.algorithm.copy cannot deduce function from argument types !()(Range, Range), candidates are:
>   C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(7808):
>     std.algorithm.copy(Range1, Range2)(Range1 source, Range2 target)
>     if (isInputRange!Range1 && isOutputRange!(Range2, ElementType!Range1))
>
> Any idea about what might be happening? I can't give a quick minimal example of the code since it is quite complex (and I failed at using dustmite trying to minimize it)

Try to reduce your Material class for a small failing example. It's probably your constructors or opAssign or something like that. Anyway, it's a bug if template errors from the implementation bubble up, so please file a report.
March 02, 2015
On Monday, 2 March 2015 at 14:14:19 UTC, Tobias Pankrath wrote:
> Try to reduce your Material class for a small failing example. It's probably your constructors or opAssign or something like that. Anyway, it's a bug if template errors from the implementation bubble up, so please file a report.
I'm still trying now, with no luck.
I also tried to get a Material[] instead of an Array!Material. It compiles, but when I call std.algorithm.sort on it I get another funny error, which apparently not even google can find except for one lonely test unit:

C:\D\dmd2\windows\bin\..\..\src\phobos\std\range.d(2222): Error: cannot have parameter of function type void()
C:\D\dmd2\windows\bin\..\..\src\phobos\std\range.d(2278): Error: cannot have parameter of function type void()
C:\D\dmd2\windows\bin\..\..\src\phobos\std\range.d(2306): Error: cannot have parameter of function type void()

Following a few more lines concerning who tried to instantiate it:
....\src\phobos\std\range.d(8385): Error: template instance std.range.stride!(Material[]) error instantiating
....\src\phobos\std\algorithm.d(9383): instantiated from here: SortedRange!(Material[], "a.step < b.step")
....\material.d(15): instantiated from here: sort!("a.step < b.step", cast (SwapStrategy)0, Material[])

(".step" is a class member variable, it's a simple int)
I'm really clueless... :P
March 02, 2015
On Mon, 02 Mar 2015 14:40:50 +0000, Francesco Cattoglio wrote:

did you tried to dustmite[1] it?

[1] https://github.com/CyberShadow/DustMite/wiki

March 02, 2015
On Monday, 2 March 2015 at 14:46:31 UTC, ketmar wrote:
> On Mon, 02 Mar 2015 14:40:50 +0000, Francesco Cattoglio wrote:
>
> did you tried to dustmite[1] it?
>
> [1] https://github.com/CyberShadow/DustMite/wiki

I tried to "dub dustmite", but it failed with a "object.Exception@DustMite\dustmite.d(220): Initial test fails"

The dustmite version is the one that was bundled with dmd 2.066.1-rc2.

I'll update dmd in the mean time, but I have a feeling that this is not related.
March 02, 2015
> I'm really clueless... :P

Something is wrong with your Material class, but you'll need to show us a reduced example.
March 02, 2015
On Monday, 2 March 2015 at 15:01:55 UTC, Tobias Pankrath wrote:
>> I'm really clueless... :P
>
> Something is wrong with your Material class, but you'll need to show us a reduced example.

After a really long time I finally found what was wrong.

http://dpaste.dzfl.pl/16d202b7124d

Wow, I honestly could have NEVER foreseen this.
This is all it takes for a class being unusable in a std.container.Array
class MyClass
{
	void init();
}
March 02, 2015
On Monday, 2 March 2015 at 15:14:49 UTC, Francesco Cattoglio wrote:
> On Monday, 2 March 2015 at 15:01:55 UTC, Tobias Pankrath wrote:
>>> I'm really clueless... :P
>>
>> Something is wrong with your Material class, but you'll need to show us a reduced example.
>
> After a really long time I finally found what was wrong.
>
> http://dpaste.dzfl.pl/16d202b7124d
>
> Wow, I honestly could have NEVER foreseen this.
> This is all it takes for a class being unusable in a std.container.Array
> class MyClass
> {
> 	void init();
> }

.init is a special property of every type: http://dlang.org/property.html#init

March 02, 2015
On 03/02/2015 07:14 AM, Francesco Cattoglio wrote:
> On Monday, 2 March 2015 at 15:01:55 UTC, Tobias Pankrath wrote:
>>> I'm really clueless... :P
>>
>> Something is wrong with your Material class, but you'll need to show
>> us a reduced example.
>
> After a really long time I finally found what was wrong.
>
> http://dpaste.dzfl.pl/16d202b7124d
>
> Wow, I honestly could have NEVER foreseen this.
> This is all it takes for a class being unusable in a std.container.Array
> class MyClass
> {
>      void init();
> }

Existing issue:

  https://issues.dlang.org/show_bug.cgi?id=12545

Ali