RepositoryC++USUnited States
MP

mpark/variant

C++17 `std::variant` for C++11/14/17

716stars
90forks
9issues
4views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: variant

#1 Repository of the week

1
TINIX TRENDING·Topic: cpp14

#1 Repository of the week

1
TINIX TRENDING·Topic: polymorphism

#1 Repository of the week

MPark.Variant

C++17 std::variant for C++11/14/17

release header travis appveyor license godbolt wandbox

Introduction

MPark.Variant is an implementation of C++17 std::variant for C++11/14/17.

Documentation

Integration

Single Header

The single-header branch provides a standalone variant.hpp file for each release. Copy it and #include away!

Submodule

You can add mpark/variant as a submodule to your project.

git submodule add https://github.com/mpark/variant.git 3rdparty/variant

Add the include directory to your include path with -I3rdparty/variant/include then #include the variant.hpp header with #include <mpark/variant.hpp>.

If you use CMake, you can simply use add_subdirectory(3rdparty/variant):

cmake_minimum_required(VERSION 3.6.3)

project(HelloWorld CXX)

add_subdirectory(3rdparty/variant)

add_executable(hello-world hello_world.cpp)
target_link_libraries(hello-world mpark_variant)

Installation / CMake find_package

git clone https://github.com/mpark/variant.git
mkdir variant/build && cd variant/build
cmake ..
cmake --build . --target install

This will install mpark/variant to the default install-directory for your platform (/usr/local for Unix, C:\Program Files for Windows). You can also install at a custom location via the CMAKE_INSTALL_PREFIX variable, (e.g., cmake .. -DCMAKE_INSTALL_PREFIX=/opt).

The installed mpark/variant can then be found by CMake via find_package:

cmake_minimum_required(VERSION 3.6.3)

project(HelloWorld CXX)

find_package(mpark_variant 1.3.0 REQUIRED)

add_executable(hello-world hello_world.cpp)
target_link_libraries(hello-world mpark_variant)

CMake will search for mpark/variant in its default set of installation prefixes. If mpark/variant is installed in a custom location via the CMAKE_INSTALL_PREFIX variable, you'll likely need to use the CMAKE_PREFIX_PATH to specify the location (e.g., cmake .. -DCMAKE_PREFIX_PATH=/opt).

Requirements

This library requires a standard conformant C++11 compiler. The following compilers are continously tested:

CompilerOperating SystemVersion String
GCC 4.8.5Ubuntu 16.04.6 LTSg++-4.8 (Ubuntu 4.8.5-4ubuntu8~16.04.1) 4.8.5
GCC 4.9.4Ubuntu 16.04.6 LTSg++-4.9 (Ubuntu 4.9.4-2ubuntu1~16.04) 4.9.4
GCC 5.5.0Ubuntu 16.04.6 LTSg++-5 (Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010
GCC 6.5.0Ubuntu 16.04.6 LTSg++-6 (Ubuntu 6.5.0-2ubuntu1~16.04) 6.5.0 20181026
GCC 7.4.0Ubuntu 16.04.6 LTSg++-7 (Ubuntu 7.4.0-1ubuntu116.04ppa1) 7.4.0
GCC 8.3.0Ubuntu 16.04.6 LTSg++-8 (Ubuntu 8.3.0-16ubuntu3~16.04) 8.3.0
GCC 9.2.1Ubuntu 16.04.6 LTSg++-9 (Ubuntu 9.2.1-17ubuntu1~16.04) 9.2.1 20191102
Clang 3.6.2Ubuntu 16.04.6 LTSUbuntu clang version 3.6.2-3ubuntu2 (tags/RELEASE_362/final) (based on LLVM 3.6.2)
Clang 3.7.1Ubuntu 16.04.6 LTSUbuntu clang version 3.7.1-2ubuntu2 (tags/RELEASE_371/final) (based on LLVM 3.7.1)
Clang 3.8.0Ubuntu 16.04.6 LTSclang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Clang 3.9.1Ubuntu 16.04.6 LTSclang version 3.9.1-4ubuntu3~16.04.2 (tags/RELEASE_391/rc2)
Clang 4.0.0Ubuntu 16.04.6 LTSclang version 4.0.0-1ubuntu1~16.04.2 (tags/RELEASE_400/rc1)
Clang 5.0.0Ubuntu 16.04.6 LTSclang version 5.0.0-3~16.04.1 (tags/RELEASE_500/final)
Clang 6.0.0Ubuntu 16.04.6 LTSclang version 6.0.0-1ubuntu2~16.04.1 (tags/RELEASE_600/final)
Clang 7.1.0Ubuntu 16.04.6 LTSclang version 7.1.0-svn353565-1exp120190408084827.60 (branches/release_70)
Clang 8.0.1Ubuntu 16.04.6 LTSclang version 8.0.1-svn369350-1exp120190820122438.78 (branches/release_80)
Clang Xcode 8.3Darwin Kernel Version 16.7.0 (OS X 10.12.6)Apple LLVM version 8.1.0 (clang-802.0.42)
Clang Xcode 9.4Darwin Kernel Version 17.4.0 (OS X 10.13.3)Apple LLVM version 9.1.0 (clang-902.0.39.2)
Clang Xcode 10.1Darwin Kernel Version 17.7.0 (OS X 10.13.6)Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Visual Studio 14 2015Visual Studio 2015 with Update 3MSVC 19.0.24241.7
Visual Studio 15 2017Visual Studio 2017 with Update 8MSVC 19.15.26732.1
Visual Studio 15 2017Visual Studio 2017 with Update 9MSVC 19.16.27025.1
Visual Studio 15 2017 (Clang/LLVM)Visual Studio 2017Clang 7.0.0

NOTES

  • GCC 4.8/4.9: constexpr support is not available for visit and relational operators.
  • Enabling libc++ std::variant tests require -std=c++17 support.

CMake Variables

  • MPARK_VARIANT_INCLUDE_TESTS:STRING (default: "")

    Semicolon-separated list of tests to build. Possible values are mpark, and libc++.

    NOTE: The libc++ std::variant tests are built with -std=c++17.

Unit Tests

Refer to test/README.md.

License

Distributed under the Boost Software License, Version 1.0.

Similar Projects

Discover other similar projects and AI models.

RepositoryC++
changkun/modern-cpp-tutorial

📚 Modern C++ Tutorial: C++11 to C++26 On the Fly | https://changkun.de/modern-cpp/

26.0k
Nov 9, 2026
Repository
AnthonyCalandra/modern-cpp-features

A cheatsheet of modern C++ language and library features.

22.0k
Oct 24, 2026
RepositoryHTML
federico-busato/Modern-CPP-Programming

Modern C++ Programming Course (C++03/11/14/17/20/23/26)

16.3k
Apr 19, 2026
RepositoryC++
0voice/cpp_new_features

2021年最新整理, C++ 学习资料,含C++ 11 / 14 / 17 / 20 / 23 新特性、入门教程、推荐书籍、优质文章、学习笔记、教学视频等

6.4k
Jun 18, 2025
RepositoryC++
0voice/cpp_new_features

2021年最新整理, C++ 学习资料,含C++ 11 / 14 / 17 / 20 / 23 新特性、入门教程、推荐书籍、优质文章、学习笔记、教学视频等

6.4k
Jun 18, 2025
RepositoryC++
NVIDIA/thrust

[ARCHIVED] The C++ parallel algorithms library. See https://github.com/NVIDIA/cccl

5.0k
Feb 8, 2024
RepositoryC++
andreasfertig/cppinsights

C++ Insights - See your source code with the eyes of a compiler

4.7k
Oct 26, 2026
RepositoryC++
rutura/The-C-20-Masterclass-Source-Code

Source code for the C++ 20 Masterclass on udemy

2.3k
Oct 29, 2026
RepositoryHTML
rigtorp/awesome-modern-cpp

A collection of resources on modern C++

13.2k
Oct 5, 2026