Remarks on std.container

James Miller james at aatch.net
Thu Mar 8 02:53:03 PST 2012


On 8 March 2012 23:16, Matthias Walter <xammy at xammy.homelinux.net> wrote:
> On 03/08/2012 10:48 AM, James Miller wrote:
>> On Thursday, March 08, 2012 10:21:48 Matthias Walter wrote:
>>> but the following did not work:
>>>
>>> std.algorithm.swap(arrayInstance[i], arrayInstance[j]);
>>
>> What error did you get exactly? Since that exact call should work. "It
>> didn't work" doesn't help.
>
> Of course - sorry for the imprecise description:
>
>
> import std.container;
> import std.algorithm;
>
> int main(char[][] args)
> {
>  auto c = Array!(double)(cast(double[]) []);
>  c.insertBack(1.0);
>  c.insertBack(2.0);
>  std.algorithm.swap(c[0], c[1]);
>
>  return 0;
> }
>
> yields:
>
> main.d(9): Error: template std.algorithm.swap(T) if (isMutable!(T) &&
> !is(typeof(T.init.proxySwap(T.init)))) does not match any function
> template declaration
> main.d(9): Error: template std.algorithm.swap(T) if (isMutable!(T) &&
> !is(typeof(T.init.proxySwap(T.init)))) cannot deduce template function
> from argument types !()(double,double)
>
>
> Best regards,
>
> Matthias

According to this double is not mutable, which makes sense, I think it
might be because opIndex on Array doesn't return a reference.

This seems like a bug to me, however its probably better to implement
the swap for Array in array, due to weirdness with returning refs for
operator overloads. File a bug report on it.

--
James Miller


More information about the Digitalmars-d-learn mailing list