toggle method

bool toggle(
  1. T value
)

Adds value to the set if not exists, removes value from the set otherwise.

Implementation

bool toggle(T value) {
  if (contains(value)) {
    remove(value);
    return false;
  } else {
    add(value);
    return true;
  }
}