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

1 import std.algorithm.comparison : equal;
2 import std.range : iota;
3 
4 auto lower = unicode.LowerCase;
5 auto upper = unicode.UpperCase;
6 auto ascii = unicode.ASCII;
7 
8 assert((lower & upper).empty); // no intersection
9 auto lowerASCII = lower & ascii;
10 assert(lowerASCII.byCodepoint.equal(iota('a', 'z'+1)));
11 // throw away all of the lowercase ASCII
12 assert((ascii - lower).length == 128 - 26);
13 
14 auto onlyOneOf = lower ~ ascii;
15 assert(!onlyOneOf['Δ']); // not ASCII and not lowercase
16 assert(onlyOneOf['$']); // ASCII and not lowercase
17 assert(!onlyOneOf['a']); // ASCII and lowercase
18 assert(onlyOneOf['я']); // not ASCII but lowercase
19 
20 // throw away all cased letters from ASCII
21 auto noLetters = ascii - (lower | upper);
22 assert(noLetters.length == 128 - 26*2);

Meta

Suggestion Box / Bug Report