Error using `equal` with various string types

monarch_dodra monarchdodra at gmail.com
Sun Feb 24 04:02:46 PST 2013


On Sunday, 24 February 2013 at 11:35:28 UTC, Jonathan M Davis 
wrote:
> On Sunday, February 24, 2013 12:24:21 monarch_dodra wrote:
>> On Sunday, 24 February 2013 at 04:47:41 UTC, Jonathan M Davis
>> 
>> wrote:
>> > However, now that I think about it, equal takes a predicate, 
>> > so
>> > it would
>> > probably work to do something like
>> > 
>> > equal!"equal(a, b)"(["hello"d], ["hello"]);
>> > 
>> > - Jonathan M Davis
>> 
>> Yes, and you don't even need to use a mixin.
>> 
>> This is a known "issue", and is specifically covered and
>> "pseudo-documented" the source unittests.
>> 
>> Copy pasted straight from the source:
>> 
>> //Should not compile, because "string == dstring" is illegal
>> static assert(!is(typeof(equal(["hello", "world"], ["hello"d,
>> "world"d]))));
>> //However, arrays of non-matching string can be compared using
>> equal!equal. Neat-o!
>> equal!equal(["hello", "world"], ["hello"d, "world"d]);
>
> Given that equal is a templated function, I'm surprised that 
> it's possible to
> pass it without it being fully instantiated. Usually, templates 
> have to be
> fully instantiated before you can alias them.
>
> - Jonathan M Davis

My first reaction when I stumbled upon it actually. Then again, 
can't the same be said about lambas? Technically, they *are* 
templates, since the type is determined when they are actually 
called.

Also, when you say "alias", do you mean "pass as alias 
parameter", or the actual "alias"? Because templates can be 
aliased un parametrized.

import std.algorithm, std.stdio;

void main()
{
     alias map2 = map;
     writeln(map2!"a * 2"([1, 2, 3]));
}


More information about the Digitalmars-d-learn mailing list