A C++17 std::variant implementation for C++11/14/17 compilers, providing type-safe unions.
MPark.Variant is a C++ library that implements the C++17 `std::variant` type for compilers supporting C++11, C++14, or C++17. It provides a type-safe union container that can hold one of several alternative types, enabling modern sum type semantics in codebases that cannot yet upgrade to C++17. The library solves the problem of accessing variant features without requiring the latest compiler standard.
C++ developers working on projects constrained to C++11/14 who need type-safe union functionality, or those seeking a portable, well-tested `std::variant` implementation across multiple compiler versions.
Developers choose MPark.Variant for its strict adherence to the C++17 standard, single-header simplicity, and extensive compiler support. It is derived from the author's implementation for libc++, ensuring high-quality conformance and reliability.
C++17 std::variant for C++11/14/17
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Derived from the author's libc++ implementation and continuously tested against libc++'s std::variant test suite, ensuring it faithfully replicates C++17 behavior.
Supports a broad range of compilers from GCC 4.8.5 to modern Clang and MSVC versions, as detailed in the extensive requirements table.
Available as a standalone variant.hpp file for easy drop-in usage without build system complexity, as highlighted in the single-header branch.
Offers CMake support for installation and find_package, facilitating seamless integration into CMake-based projects with add_subdirectory or custom prefixes.
For GCC 4.8 and 4.9, constexpr is not available for visit and relational operators, restricting compile-time usage in legacy environments.
Adds a third-party library to the project, which may conflict with teams minimizing dependencies or preferring standard library-only solutions.
Relies on external cppreference.com for documentation, lacking detailed examples, tutorials, or troubleshooting guides within the repository.