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);
Sets support natural syntax for set algebra, namely: