InversionList.opBinary

Sets support natural syntax for set algebra, namely:

OperatorMath notationDescription
&a ∩ bintersection
|a ∪ bunion
-a ∖ bsubtraction
~a ~ bsymmetric set difference i.e. (a ∪ b) \ (a ∩ b)
struct InversionList(SP = GcPolicy)
This
opBinary
(
string op
U
)
(
U rhs
)
if (
is(U : dchar)
)

Examples

import std.algorithm.comparison : equal;
import std.range : iota;

auto lower = unicode.LowerCase;
auto upper = unicode.UpperCase;
auto ascii = unicode.ASCII;

assert((lower & upper).empty); // no intersection
auto lowerASCII = lower & ascii;
assert(lowerASCII.byCodepoint.equal(iota('a', 'z'+1)));
// throw away all of the lowercase ASCII
assert((ascii - lower).length == 128 - 26);

auto onlyOneOf = lower ~ ascii;
assert(!onlyOneOf['Δ']); // not ASCII and not lowercase
assert(onlyOneOf['$']); // ASCII and not lowercase
assert(!onlyOneOf['a']); // ASCII and lowercase
assert(onlyOneOf['я']); // not ASCII but lowercase

// throw away all cased letters from ASCII
auto noLetters = ascii - (lower | upper);
assert(noLetters.length == 128 - 26*2);

Meta