www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Equality of `pred` Template Parameters

reply "Per =?UTF-8?B?Tm9yZGzDtnci?= <per.nordlow gmail.com> writes:
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!
Aug 17 2015
parent reply "Per =?UTF-8?B?Tm9yZGzDtnci?= <per.nordlow gmail.com> writes:
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?
Aug 17 2015
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
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");
Aug 17 2015
next sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
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.
Aug 17 2015
prev sibling parent "Per =?UTF-8?B?Tm9yZGzDtnci?= <per.nordlow gmail.com> writes:
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?
Aug 17 2015