On Wednesday, 7 August 2013 at 09:12:41 UTC, monarch_dodra wrote:
Also, and this is important (!): A lambda is *always unique*, whereas strings alias each other. This means that:

sort!"a > b"(1, 2, 3); //Both generate the same template
sort!"a > b"(1, 2, 3); //

sort!((a, b) => a > b)(1, 2, 3); //Generates two different templates
sort!((a, b) => a > b)(1, 2, 3);

This is particularly relevant for *struct* that take preds.

Imagine:
Sorter!"a > b" sorter1;
Sorter!"a > b" sorter2;
static assert(typeof(sorter1) == typeof(sorter2)); //Passes

But
Sorter!((a, b) => a > b) sorter1;
Sorter!((a, b) => a > b) sorter2;
static assert(typeof(sorter1) == typeof(sorter2)); //Fails

Ew. I don't see this as a good argument. Code and strings are fundamentally different.

All the following functionally equivalent string lambdas will produce different instantiations of Sorter:

    "a > b"
    "b < a"
    "a<b"
    " a < b"

etc.

Reply via email to