View source code
Display the source code in std/uni.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.uni.InversionList.opBinary

Sets support natural syntax for set algebra, namely:

Operator Math notation Description
& a ∩ b intersection
| a ∪ b union
- a ∖ b subtraction
~ a ~ b symmetric set difference i.e. (a ∪ b) \ (a ∩ b)

This opBinary(string op, U) (
  U rhs
)
if (isCodepointSet!U || is(U : dchar));

Example

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
writeln((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);
writeln(noLetters.length); // 128 - 26 * 2

Authors

Dmitry Olshansky

License

Boost License 1.0.