Thread overview
Equality of `pred` Template Parameters
Aug 17, 2015
Per Nordlöw
Aug 17, 2015
Per Nordlöw
Aug 17, 2015
Timon Gehr
Aug 17, 2015
Timon Gehr
Aug 17, 2015
Per Nordlöw
August 17, 2015
In https://github.com/D-Programming-Language/phobos/pull/3534

I'm in need of a generic and correct definition of

    template isSortedRange(T, alias pred = "a < b")

at

https://github.com/D-Programming-Language/phobos/pull/3534/files#diff-9f63c74383984a09f5bf578493892e27R1005

To make it general we want it to support `pred` argument of types other than `string`, typically

    binaryFun!"a < b"

Specifically, we want `isSortedRange` to "understand" that

    binaryFun!"a < b"
    binaryFun!"a<b"

are equvialent and

    binaryFun!"a < b"
    binaryFun!"a > b"

are not (opposites). I'm guessing there is compile-time-parsing somewhere in Phobos that already does this. Could/Should this be extracted and reused?

Destroy!
August 17, 2015
On Monday, 17 August 2015 at 09:23:56 UTC, Per Nordlöw wrote:
> To make it general we want it to support `pred` argument of types other than `string`, typically

If binaryFun!"..." are used as template alias parameters in all cases is it currently possible to compare these lambdas for equality?
August 17, 2015
On 08/17/2015 12:13 PM, "Per =?UTF-8?B?Tm9yZGzDtnci?= <per.nordlow@gmail.com>" wrote:
> On Monday, 17 August 2015 at 09:23:56 UTC, Per Nordlöw wrote:
>> To make it general we want it to support `pred` argument of types
>> other than `string`, typically
>
> If binaryFun!"..." are used as template alias parameters in all cases is
> it currently possible to compare these lambdas for equality?

import std.functional: binaryFun;

alias x=binaryFun!"a+b";
alias y=binaryFun!"a+b";
alias z=binaryFun!"a-b";
static assert(__traits(isSame,x,y));
static assert(!__traits(isSame,y,z));

enum binaryFunString(alias x:binaryFun!T,T...)=T[0];

static assert(binaryFunString!x=="a+b");
static assert(binaryFunString!y=="a+b");
static assert(binaryFunString!z=="a-b");

August 17, 2015
On 08/17/2015 02:33 PM, Timon Gehr wrote:
> enum binaryFunString(alias x:binaryFun!T,T...)=T[0];
>
> static assert(binaryFunString!x=="a+b");
> static assert(binaryFunString!y=="a+b");
> static assert(binaryFunString!z=="a-b");

Note that the remaining template arguments to binaryFun are important as well, they give the parameter names.

You might want to use std.traits.TemplateArgsOf.
August 17, 2015
On Monday, 17 August 2015 at 12:33:28 UTC, Timon Gehr wrote:
> import std.functional: binaryFun;
>
> alias x=binaryFun!"a+b";
> alias y=binaryFun!"a+b";
> static assert(__traits(isSame,x,y));

Not quite what we want, because

    alias x=binaryFun!"a+b";
    alias y=binaryFun!"a + b";
    static assert(__traits(isSame,x,y));

fails for me.

Can we be dumb for now and just remove space in string?