On Friday, 25 October 2019 at 15:52:50 UTC, Paul Backus wrote:
On Friday, 25 October 2019 at 09:25:21 UTC, Dennis wrote:
I can overload the 'in' operator on my types to something that
takes exponential time if I want, just like "+" can also be
overloaded to a linear time operation on e.g. BigInt.
Worth noting that `opIn` is a D1 operator overload, and thus
deprecated as of 2.088.0.
That wasn't mentioned though? Does it reverse the arguments so
that the writeln() examples below can be more naturally ordered?
#! /usr/bin/env rdmd
import std.stdio;
struct X {
string data;
bool opBinary(string op)(char p) if (op == "in") {
foreach (c; data)
if (p == c) return true;
return false;
}
}
void main() {
auto x = X("hi there");
writeln(x in 'i');
writeln(x in '?');
}