templating opEquals/opCmp (e.g. for DSL/expression templates)
John Colvin
john.loughran.colvin at gmail.com
Wed Feb 13 16:49:47 UTC 2019
On Tuesday, 12 February 2019 at 04:15:34 UTC, Nicholas Wilson
wrote:
> With opBinary and opUnary it is possible to create types that
> span the binary and unary operators. However opEquals can only
> be used to types that compare for equality not inequality,
> since a == b -> a.opEquals(b) can return whatever type it likes
> but a == b -> !(a.opEquals(b)) returns a bool. opCmp can't be
> used at all since a <=> b -> a.opCmp(b) <=> 0 which evaluates
> to a bool.
>
> I propose that in addition to the current (non-template) forms
> of opCmp/opEquals
>
> struct A { bool opEquals(A rhs); int opCmp(A rhs); }
>
> we allow
>
> struct B
> {
> T opEquals(string op)(B rhs); // op is "<" "<=" etc.
> T opCmp(string op)(B rhs); // op is "==" "!="
> }
>
> where T is any arbitrary type.
>
> see also
> https://github.com/k3kaimu/dranges/blob/master/source/dranges/_lambda.d
Any argument about this should consider what was necessary to
make std.typecons.Proxy work properly for floating point.
https://github.com/dlang/phobos/pull/3927
and the original forum discussion
https://forum.dlang.org/post/vfgawgvzzfgjhshavmlq@forum.dlang.org
More information about the Digitalmars-d
mailing list