add element to set
Fill set from range
create difference of two sets
create intersection of two sets
iterate over items
join other set to this set
number of items in set
if element present in set
remove element from set
import std.stdio; Set!string s; s.add("hello"); assert(s.length == 1); assert(equal(s.iterate, only("hello"))); s.remove("hello"); assert(s.length == 0); s.remove("hello"); assert(s.length == 0); s.create(only("hello", "hello", "world")); assert(s.length == 2); s.join(set(only("and", "bye"))); assert(s.length == 4); auto other = set(only("and", "bye", "!")); auto cross0 = s.intersection(other); assert("bye" in cross0); assert("!" !in cross0); auto cross1 = other.intersection(s); assert(cross0.length == cross1.length); assert("and" in cross0 && "and" in cross1); assert("bye" in cross0 && "bye" in cross1); auto nums = set(iota(10)); auto someNums = nums.difference(set(only(1,2,3))); assert(0 in someNums); assert(1 !in someNums); bool f(const Set!string s) { return "yes" in s; } Set!string ss; ss.add("yes"); f(ss); assert("yes" in ss);
Set structure