Impove Std::variant implementation
This fixes several bugs/incompatibilities and makes the code (hopefully) a little more robust and better to understand. It's the result of the discussion with @lasse.hinrichsen.
This should also fix the problem in dune-localfunctions!113 (merged)
- Remove explicit
Buffer
class and usealigned_storage
directly - Use a single
TypeStorage
implementation for all types - Rename
variant_union_
to `VariadicUnion* - Clean up interfaces and implementation of
TypeStorage
andVariadicUnion
- Only allow (default) construction of empty objects
- Only allow move assignment. The rhs must be empty, but this can neither be checked statically nor dynamically.
- All construction and assignment is done using special
construct()
andassign()
methods. - Destruction is only done using the
destruct()
method.
-
Impl::variant_
does no longer rely on standard construction and assignment operators (despite the two exceptions) but uses the new special methods
This fixes several bugs and incompatibilities of the old implementation:
- Non-trivial types are no longer copied binary.
- Destructors are now called properly.
- Copy/move assignment now decays to copy/move assignment of the stored value if it already has the target type.
- Unnecessary copies are avoided.