mpark / variant

C++17 `std::variant` for C++11/14/17
https://mpark.github.io/variant
Boost Software License 1.0
659 stars 88 forks source link

Determine which functions should not throw and handle the corrupted state #2

Closed mpark closed 8 years ago

mpark commented 8 years ago

Suppose variant<T, U> v; is corrupted. Should variant<T, U> w(v) throw a bad_variant_access exception? or should w simply also be corrupted?

Suppose variant<T, U> v, w; are both corrupted. Should swap(v, w) throw a bad_variant_access exception? or should it be a no-op?

The full list of operations that need to be considered:

mpark commented 8 years ago
  1. Construction and assignment from a corrupted variant leaves the target variant in a corrupted state.
  2. Hashing a corrupted variant returns tuple_not_found.
  3. Swapping with corrupted variants simply swaps the states.
  4. Relational operators do not throw in the presence of corrupted variants. v == w where both v and w are corrupted returns true, v < w where both v and w are corrupted returns false. Corrupted variants are considered to be greater than uncorrupted ones based on the index.
mpark commented 8 years ago

https://github.com/mpark/variant/commit/1e4f17fd2c4564cda26748f0619ba6b272a95342