2017-06-03 14:57:30 +03:00
2017-06-03 14:57:30 +03:00
2017-05-29 17:31:05 +03:00
2017-06-03 00:27:52 +03:00
2017-05-29 16:31:42 +03:00
2017-05-31 07:59:35 +03:00
2017-05-31 07:59:35 +03:00
2017-06-03 14:26:24 +03:00

variant2

This repository contains a never-valueless C++14 implementation of std::variant in variant.hpp and an implementation of expected<T, E...> in expected.hpp that is an extended version of extended<T, E> as proposed in P0323R1 and the subsequent D0323R2.

The code requires mp11 and Boost.Config. The repository is intended to be placed into the libs/variant2 directory of a Boost clone or release, with mp11 in libs/mp11, but the headers will also work standalone if mp11.hpp or mp11_single.hpp is included beforehand.

Supported compilers:

  • g++ 5 or later with -std=c++14 or -std=c++1z
  • clang++ 3.5 or later with -std=c++14 or -std=c++1z
  • Visual Studio 2017

variant.hpp

The class boost::variant2::variant<T...> is an almost conforming implementation of std::variant with the following differences:

  • The function valueless_by_exception() is not present, as the variant is never valueless;
  • A converting constructor from, e.g. variant<int, float> to variant<float, double, int> is provided as an extension;
  • The reverse operation, going from variant<float, double, int> to variant<int, float> is provided as the member function subset<U...>. (This operation can throw if the current state of the variant cannot be represented.)

To avoid the valueless state, this implementation falls back to using double storage unless

  • all the contained types are nothrow move constructible, or
  • at least one contained type has a nothrow default constructor.

If the second bullet doesn't hold, but the first does, the variant uses single storage, but emplace constructs a temporary and moves it into place if the construction of the object can throw. In case this is undesirable, the recommended practice is to add an alternative that has a nonthrowing default constructor.

expected.hpp

The class boost::variant2::expected<T, E...> represents the return type of an operation that may potentially fail. It contains either the expected result of type T, or a reason for the failure of one of the error types in E.... Internally, this is represented as variant<T, E...>.

Description
A never-valueless, strong guarantee implementation of std::variant
Readme 1,019 KiB
Languages
C++ 98.4%
CMake 0.9%
Shell 0.3%
Batchfile 0.3%
HTML 0.1%