SERVER-77274 Delete src/third_party/variant-1.4.0 library

This commit is contained in:
Mark Benvenuto 2023-06-08 10:59:54 -04:00 committed by Evergreen Agent
parent 771a07f38d
commit d0244666a9
42 changed files with 0 additions and 5547 deletions

View File

@ -54,7 +54,6 @@ a notice will be included in
| [Unicode] | Unicode-DFS-2015 | 8.0.0 | ✗ | ✗ | | [Unicode] | Unicode-DFS-2015 | 8.0.0 | ✗ | ✗ |
| [libunwind] | MIT | 1.6.2 + changes | | ✗ | | [libunwind] | MIT | 1.6.2 + changes | | ✗ |
| [Valgrind] | BSD-3-Clause<sup>\[<a href="#note_vg" id="ref_vg">1</a>]</sup> | 3.17.0 | | ✗ | | [Valgrind] | BSD-3-Clause<sup>\[<a href="#note_vg" id="ref_vg">1</a>]</sup> | 3.17.0 | | ✗ |
| [variant] | BSL-1.0 | 1.4.0 | | ✗ |
| [wiredtiger] | | <sup>\[<a href="#note_wt" id="ref_wt">2</a>]</sup> | ✗ | ✗ | | [wiredtiger] | | <sup>\[<a href="#note_wt" id="ref_wt">2</a>]</sup> | ✗ | ✗ |
| [yaml-cpp] | MIT | 0.6.2 | | ✗ | | [yaml-cpp] | MIT | 0.6.2 | | ✗ |
| [Zlib] | Zlib | 1.2.13 | ✗ | ✗ | | [Zlib] | Zlib | 1.2.13 | ✗ | ✗ |
@ -88,7 +87,6 @@ a notice will be included in
[Unicode]: http://www.unicode.org/versions/enumeratedversions.html [Unicode]: http://www.unicode.org/versions/enumeratedversions.html
[libunwind]: http://www.nongnu.org/libunwind/ [libunwind]: http://www.nongnu.org/libunwind/
[Valgrind]: http://valgrind.org/downloads/current.html [Valgrind]: http://valgrind.org/downloads/current.html
[variant]: https://github.com/mpark/variant
[wiredtiger]: https://github.com/wiredtiger/wiredtiger [wiredtiger]: https://github.com/wiredtiger/wiredtiger
[yaml-cpp]: https://github.com/jbeder/yaml-cpp/releases [yaml-cpp]: https://github.com/jbeder/yaml-cpp/releases
[Zlib]: https://zlib.net/ [Zlib]: https://zlib.net/

View File

@ -1495,32 +1495,6 @@ all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by works are solely in the form of machine-executable object code generated by
a source language processor. a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
24) License notice for MPark.Variant
-------------------------------------
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT

View File

@ -255,13 +255,6 @@ components:
team_owner: "Query" team_owner: "Query"
upgrade_suppression: TODO SERVER-64574 upgrade_suppression: TODO SERVER-64574
"mpark-variant-devel":
homepage_url: https://github.com/mpark/variant
open_hub_url: N/A
release_monitoring_id: 18301
local_directory_path: src/third_party/variant-1.4.0
team_owner: "Service Architecture"
nlohmann.json.decomposed: nlohmann.json.decomposed:
homepage_url: https://github.com/nlohmann/json homepage_url: https://github.com/nlohmann/json
open_hub_url: https://www.openhub.net/p/nlohmann_json open_hub_url: https://www.openhub.net/p/nlohmann_json

View File

@ -18,7 +18,6 @@ Import([
snappySuffix = '-1.1.7' snappySuffix = '-1.1.7'
icuSuffix = '-57.1' icuSuffix = '-57.1'
tomcryptSuffix = '-1.18.2' tomcryptSuffix = '-1.18.2'
variantSuffix = '-1.4.0'
thirdPartyEnvironmentModifications = { thirdPartyEnvironmentModifications = {
'abseil-cpp': {'CPPPATH': ['#/src/third_party/abseil-cpp/dist'], }, 'abseil-cpp': {'CPPPATH': ['#/src/third_party/abseil-cpp/dist'], },
@ -38,7 +37,6 @@ thirdPartyEnvironmentModifications = {
}, },
'timelib': {'CPPPATH': ['#/src/third_party/timelib'], }, 'timelib': {'CPPPATH': ['#/src/third_party/timelib'], },
'unwind': {}, 'unwind': {},
'variant': {'CPPPATH': ['#src/third_party/variant' + variantSuffix + '/include'], },
'mozjs': { 'mozjs': {
'CPPPATH': [ 'CPPPATH': [
'#/src/third_party/mozjs/include', '#/src/third_party/mozjs/include',
@ -327,7 +325,6 @@ s2Env.InjectThirdParty(libraries=[
'abseil-cpp', 'abseil-cpp',
'fmt', 'fmt',
'safeint', 'safeint',
'variant',
]) ])
s2Env.InjectMongoIncludePaths() s2Env.InjectMongoIncludePaths()
s2Env.SConscript('s2/SConscript', exports={'env': s2Env}) s2Env.SConscript('s2/SConscript', exports={'env': s2Env})

View File

@ -1,72 +0,0 @@
# MPark.Variant
#
# Copyright Michael Park, 2015-2017
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
build:
verbosity: detailed
branches:
only:
- master
- dev
clone_depth: 1
platform: x64
environment:
matrix:
# Visual Studio 2015
- GENERATOR: Visual Studio 14 2015 Win64
TESTS: mpark
SCRIPT: support/vs.py
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
# Previous Visual Studio 2017
- GENERATOR: Visual Studio 15 2017 Win64
STDFLAGS: /std:c++14 /std:c++17 /std:c++latest
TESTS: mpark
SCRIPT: support/vs.py
APPVEYOR_BUILD_WORKER_IMAGE: Previous Visual Studio 2017
# Visual Studio 2017
- GENERATOR: Visual Studio 15 2017 Win64
STDFLAGS: /std:c++14 /std:c++17 /std:c++latest
TESTS: mpark
SCRIPT: support/vs.py
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
# Clang/LLVM
- CC: clang-cl
CXX: clang-cl
STDFLAGS: /std:c++14 /std:c++17 /std:c++latest
TESTS: mpark
SCRIPT: support/ninja.py
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
install:
- git submodule -q update --init
# Directory for dependency installation.
- set DEPS=%APPVEYOR_BUILD_FOLDER%\deps
- mkdir %DEPS%
# Install Ninja
- set NINJA_URL="https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-win.zip"
- curl -fsSL %NINJA_URL% -o ninja.zip
- 7z x ninja.zip -o%DEPS%\ninja > nul
- set PATH=%DEPS%\ninja;%PATH%
- ninja --version
before_build:
# Enable the Visual C++ toolset for command-line builds.
- IF "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" (
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
)
- IF "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" (
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
)
build_script:
- python %SCRIPT%

View File

@ -1,359 +0,0 @@
---
BasedOnStyle: Google
# Good:
#
# class TFoo {
# public:
#
# TFoo() = default;
#
# } // TFoo
#
# Bad:
#
# class TFoo {
# public:
#
# TFoo() = default;
#
# } // TFoo
#
AccessModifierOffset: 0
### AlignEscapedNewlinesLeft: true
# Good:
#
# int x = 100; // comment1
# std::string y = "one hundred"; // comment2
#
# Bad:
#
# int x = 100; // comment1
# std::string y = "one hundred"; // comment2
#
AlignTrailingComments: false
### AllowAllParametersOfDeclarationOnNextLine: true
AllowShortIfStatementsOnASingleLine: true
# Good:
#
# while (flag)
# x = 42;
#
# Bad:
#
# while (flag) x = 42;
#
AllowShortLoopsOnASingleLine: false
# Good:
#
# const char *text =
# "hello"
# "world";
#
# Bad:
#
# const char *text = "hello"
# "world";
#
AlwaysBreakBeforeMultilineStrings: true
# Good:
#
# template <typename TVal>
# void F() {}
#
# Bad:
#
# template <typename TVal> void F() {}
#
AlwaysBreakTemplateDeclarations: true
# Good:
#
# F(first,
# second,
# third,
# fourth,
# fifth,
# sixth,
# seventh,
# eighth);
#
# Bad:
#
# F(first, second, third, fourth, fifth, sixth,
# seventh, eighth);
#
BinPackArguments: false
# Good:
#
# void F(int first,
# int second,
# int third,
# int fourth,
# int fifth,
# int sixth,
# int seventh,
# int eighth) {}
#
# Bad:
#
# void F(int first, int second, int third, int fourth, int fifth, int sixth,
# int seventh, int eighth) {}
#
BinPackParameters: false
# Good:
#
# int x = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
# bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
#
# Bad:
#
# int x = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
# + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
#
BreakBeforeBinaryOperators: false
# Good:
#
# void F() {}
#
# Bad:
#
# void F()
# {
# }
#
BreakBeforeBraces: Attach
# Good:
#
# class TFoo {
# public:
#
# TFoo()
# : Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(1),
# Bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(2) {}
#
# }; // TFoo
#
# Bad:
#
# class TFoo {
# public:
#
# TFoo()
# : Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(1)
# , Bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(2) {}
#
# }; // TFoo
#
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 80
# Good:
#
# class TFoo {
# public:
#
# TFoo()
# : First(1),
# Second(2),
# Third(3),
# Fourth(4),
# Fifth(5),
# Sixth(6),
# Seventh(7),
# Eighth(8) {}
#
# }; // TFoo
#
# Bad:
#
# class TFoo {
# public:
#
# TFoo()
# : First(1), Second(2), Third(3), Fourth(4), Fifth(5), Sixth(6),
# Seventh(7), Eighth(8) {}
#
# }; // TFoo
#
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerBinding: false
# Good:
#
# int x;
# switch (x) {
# case 0: {
# x = 0;
# break;
# } // case
# case 1: {
# x = 1;
# break;
# } // case
# } // switch
#
# Bad:
#
# int x;
# switch (x) {
# case 0: {
# x = 0;
# break;
# } // case
# case 1: {
# x = 1;
# break;
# } // case
# } // switch
#
IndentCaseLabels: true
# Good:
#
# std::tuple<int, int, double, double>
# Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();
#
# Bad:
#
# std::tuple<int, int, double, double>
# Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();
#
IndentFunctionDeclarationAfterType: false
IndentWidth: 2
MaxEmptyLinesToKeep: 1
# Good:
#
# namespace Foo {
#
# class TFoo {};
#
# } // Foo
#
# Bad:
#
# namespace Foo {
#
# class TFoo {};
#
# } // Foo
#
NamespaceIndentation: All
### ObjCSpaceBeforeProtocolList: false
### PenaltyBreakComment: 60
### PenaltyBreakFirstLessLess: 120
### PenaltyBreakString: 1000
### PenaltyExcessCharacter: 1000000
### PenaltyReturnTypeOnItsOwnLine: 200
# Good:
#
# int *ptr = nullptr;
#
# Bad:
#
# int* ptr = nullptr;
#
PointerBindsToType: false
# Good:
#
# if (flag) {
# flag = true;
# } // if
#
# Bad:
#
# if(flag) {
# flag = true;
# } // if
#
SpaceAfterControlStatementKeyword: true
# Good:
#
# x = 42;
#
# Bad:
#
# x= 42;
#
SpaceBeforeAssignmentOperators: true
# Good:
#
# F();
#
# Bad:
#
# F( );
#
SpaceInEmptyParentheses: false
# Good:
#
# x = 42; // Comment
#
# Bad:
#
# x = 42; // Comment
#
SpacesBeforeTrailingComments: 2
# Good:
#
# bool y = (bool)x;
#
# Bad:
#
# bool y = ( bool )x;
#
SpacesInCStyleCastParentheses: false
# Good:
#
# if (flag) {
# flag = true;
# } // if
#
# Bad:
#
# if ( flag ) {
# flag = true;
# } // if
#
SpacesInParentheses: false
Standard: Cpp11
TabWidth: 2
UseTab: false
...

View File

@ -1,34 +0,0 @@
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# build
/build
3rdparty/benchmark
3rdparty/metabench

View File

@ -1,3 +0,0 @@
[submodule "3rdparty/googletest"]
path = 3rdparty/googletest
url = https://github.com/abseil/googletest.git

View File

@ -1,186 +0,0 @@
# MPark.Variant
#
# Copyright Michael Park, 2015-2017
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
language: cpp
dist: xenial
sudo: false
branches:
only:
- master
- dev
git:
depth: 1
env:
global:
- secure: jL8hAVoa2B512uGeoh5DL2YXrAznfKPz3GbcaUPzR6mR2Izj2yHFihLLeHrEY8vUdadS8zbn2CwtWnmJjNz5kIT/RxESxJJtgVNruwo0u4piIfxVI/tTRObMXKaGrfquDAHS/hjAhQlPSNNr+89oFSBvSfNpAVECd/ERhhnjIugD+MFFzaxi26qvM6li9toxPNJIxBq9jHRuZzlpWez6d6RcTsaqr30BaCEuJhVcg7J4SiSL8xeW2sokAG65pZ/aig23cCSJkhazbMd7Cy/OFNjQrhc2PQ+E0c2xEwdwCNA8qTnsMrUeo9NXc+lozOf23LWD1EvZtcNNG5arPhSuGGYs90T1GdL2jqyS1E+1Xf0cOWqB4VMho7H+vV55SgZb+TYDrmB63YvgxcUKgsDRvPI9bBv3S3uxgktbE6gwnrfQirKowbscC07X3R1RJiI6hSkVNdrLnQF28BHMRlCpyhDejIWm4qHgOrWCN+I6hZtk+nsRuJF8sCSFPUWuzlG+/kSwaBwm/eEy+ZI66ufJamHUqC8bxa+6kINxtJTMN79ZnbIPwOvey9cfVfzwxefaStwpQbCJuZlMbuo4738HxUQpscxgv6LA5ZEMz8hlKO82cWDZSEDxSrUowueu1Az0u5tfzBUXaU5pZCnGdK6aMGHcTznaeUFebq8uhLR3uc0=
jobs:
include:
# ubuntu 16.04, gcc-4.8
- env: VER=4.8 STDFLAGS="-std=c++11 -std=c++1y" TESTS="mpark"
compiler: gcc
os: linux
addons: { apt: { packages: ["g++-4.8", "ninja-build"],
sources: ["ubuntu-toolchain-r-test"] } }
# ubuntu 16.04, gcc-4.9
- env: VER=4.9 STDFLAGS="-std=c++11 -std=c++14" TESTS="mpark"
compiler: gcc
os: linux
addons: { apt: { packages: ["g++-4.9", "ninja-build"],
sources: ["ubuntu-toolchain-r-test"] } }
# ubuntu 16.04, gcc-5
- env: VER=5 STDFLAGS="-std=c++11 -std=c++14 -std=c++1z" TESTS="mpark"
compiler: gcc
os: linux
addons: { apt: { packages: ["g++-5", "ninja-build"],
sources: ["ubuntu-toolchain-r-test"] } }
# ubuntu 16.04, gcc-6
- env: VER=6 STDFLAGS="-std=c++11 -std=c++14 -std=c++1z" TESTS="mpark"
compiler: gcc
os: linux
addons: { apt: { packages: ["g++-6", "ninja-build"],
sources: ["ubuntu-toolchain-r-test"] } }
# ubuntu 16.04, gcc-7
- env: VER=7 STDFLAGS="-std=c++11 -std=c++14 -std=c++17" TESTS="mpark libc++"
compiler: gcc
os: linux
addons: { apt: { packages: ["g++-7", "ninja-build"],
sources: ["ubuntu-toolchain-r-test"] } }
# ubuntu 16.04, gcc-8
- env: VER=8 STDFLAGS="-std=c++11 -std=c++14 -std=c++17" TESTS="mpark libc++"
compiler: gcc
os: linux
addons: { apt: { packages: ["g++-8", "ninja-build"],
sources: ["ubuntu-toolchain-r-test"] } }
# ubuntu 16.04, clang-3.6
- env: VER=3.6 STDFLAGS="-std=c++11 -std=c++14" TESTS="mpark"
compiler: clang
os: linux
addons: { apt: { packages: ["clang-3.6", "ninja-build"] } }
# ubuntu 16.04, clang-3.7
- env: VER=3.7 STDFLAGS="-std=c++11 -std=c++14" TESTS="mpark"
compiler: clang
os: linux
addons: { apt: { packages: ["clang-3.7", "ninja-build"] } }
# ubuntu 16.04, clang-3.8
- env: VER=3.8 STDFLAGS="-std=c++11 -std=c++14" TESTS="mpark"
compiler: clang
os: linux
addons: { apt: { packages: ["clang-3.8", "ninja-build"] } }
# ubuntu 16.04, clang-3.9
- env: VER=3.9 STDFLAGS="-std=c++11 -std=c++14 -std=c++1z" TESTS="mpark"
compiler: clang
os: linux
addons: { apt: { packages: ["clang-3.9", "ninja-build"] } }
# ubuntu 16.04, clang-4.0
- env: VER=4.0 STDFLAGS="-std=c++11 -std=c++14 -std=c++1z" TESTS="mpark"
compiler: clang
os: linux
addons: { apt: { packages: ["clang-4.0", "ninja-build"] } }
# ubuntu 16.04, clang-5.0
- env: VER=5.0 STDFLAGS="-std=c++11 -std=c++14 -std=c++17" TESTS="mpark libc++"
compiler: clang
os: linux
addons: { apt: { packages: ["clang-5.0", "ninja-build"] } }
# ubuntu 16.04, clang-6.0
- env: VER=6.0 STDFLAGS="-std=c++11 -std=c++14 -std=c++17" TESTS="mpark libc++"
compiler: clang
os: linux
addons: { apt: { packages: ["clang-6.0", "ninja-build"] } }
# ubuntu 16.04, clang-7
- env: VER=7 STDFLAGS="-std=c++11 -std=c++14 -std=c++17" TESTS="mpark libc++"
compiler: clang
os: linux
addons: { apt: { packages: ["clang-7", "ninja-build"],
sources: ["llvm-toolchain-xenial-7"] } }
# OS X El Capitan 10.11
- env: STDFLAGS="-std=c++11 -std=c++14 -std=c++1z" TESTS="mpark"
compiler: clang
os: osx
osx_image: xcode7.3
# OS X Sierra 10.12
- env: STDFLAGS="-std=c++11 -std=c++14 -std=c++1z" TESTS="mpark"
compiler: clang
os: osx
osx_image: xcode8.3
# OS X High Sierra 10.13
- env: STDFLAGS="-std=c++11 -std=c++14 -std=c++17" TESTS="mpark"
compiler: clang
os: osx
osx_image: xcode9.4
# OS X High Sierra 10.13
- env: STDFLAGS="-std=c++11 -std=c++14 -std=c++17" TESTS="mpark"
compiler: clang
os: osx
osx_image: xcode10.1
- stage: deploy
name: "Single Header"
if: branch = master AND type = push
install: skip
before_script:
- git config --global user.name "Travis CI"
- git config --global user.email "<>"
- travis_retry git clone https://$GITHUB_TOKEN@github.com/mpark/variant
--depth 1 --branch=single-header single-header &>/dev/null
script:
- SHA=$(git rev-parse --short HEAD)
- python support/single-header.py > single-header/master/variant.hpp
- pushd single-header
- |
if git diff-index --quiet HEAD --; then
echo "Nothing to do. No changes were made to 'variant.hpp'."
else
git add --all
git commit -m "Updated 'variant.hpp' @${SHA}."
travis_retry git pull --rebase && git push origin single-header &>/dev/null
fi
- popd
install:
# Upgrade CMake and install Ninja on OS X.
- |
if [ "${TRAVIS_OS_NAME}" = "osx" ]; then
brew update
brew upgrade cmake
brew install ninja
fi
- cmake --version
- ninja --version
# Set the correct `CC` and `CXX` environment variables.
- |
if [ -n "${VER}" ]; then
export CC="${CC}-${VER}"
export CXX="${CXX}-${VER}"
fi
- ${CXX} --version
script:
- python support/ninja.py
notifications:
email: false

View File

@ -1,23 +0,0 @@
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

View File

@ -1,160 +0,0 @@
# MPark.Variant
> __C++17__ `std::variant` for __C++11__/__14__/__17__
[![release][badge.release]][release]
[![header][badge.header]][header]
[![travis][badge.travis]][travis]
[![appveyor][badge.appveyor]][appveyor]
[![license][badge.license]][license]
[![godbolt][badge.godbolt]][godbolt]
[![wandbox][badge.wandbox]][wandbox]
[badge.release]: https://img.shields.io/github/release/mpark/variant.svg
[badge.header]: https://img.shields.io/badge/single%20header-master-blue.svg
[badge.travis]: https://travis-ci.org/mpark/variant.svg?branch=master
[badge.appveyor]: https://ci.appveyor.com/api/projects/status/github/mpark/variant?branch=master&svg=true
[badge.license]: https://img.shields.io/badge/license-boost-blue.svg
[badge.godbolt]: https://img.shields.io/badge/try%20it-on%20godbolt-222266.svg
[badge.wandbox]: https://img.shields.io/badge/try%20it-on%20wandbox-5cb85c.svg
[release]: https://github.com/mpark/variant/releases/latest
[header]: https://github.com/mpark/variant/blob/single-header/master/variant.hpp
[travis]: https://travis-ci.org/mpark/variant
[appveyor]: https://ci.appveyor.com/project/mpark/variant
[license]: https://github.com/mpark/variant/blob/master/LICENSE.md
[godbolt]: https://godbolt.org/g/1qYDAK
[wandbox]: https://wandbox.org/permlink/QV3gZ2KQQNwgoFIB
## Introduction
__MPark.Variant__ is an implementation of __C++17__ `std::variant` for __C++11__/__14__/__17__.
- Based on [my implementation of `std::variant` for __libc++__][libcxx-impl]
- Continuously tested against __libc++__'s `std::variant` test suite.
[libcxx-impl]: https://reviews.llvm.org/rL288547
## Documentation
- [cppreference.com](http://en.cppreference.com/w/cpp/utility/variant)
- [eel.is/c++draft](http://eel.is/c++draft/variant)
## Integration
### Single Header
The [single-header] branch provides a standalone `variant.hpp`
file for each [release](https://github.com/mpark/variant/releases).
Copy it and `#include` away!
[single-header]: https://github.com/mpark/variant/tree/single-header
### Submodule
You can add `mpark/variant` as a submodule to your project.
```bash
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
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`
```bash
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
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:
| Compiler | Operating System | Version String |
| -------------------------------------- | ------------------------------------------- | ---------------------------------------------------------------------------------- |
| GCC 4.8.5 | Ubuntu 16.04.5 LTS | g++-4.8 (Ubuntu 4.8.5-4ubuntu8~16.04.1) 4.8.5 |
| GCC 4.9.4 | Ubuntu 16.04.5 LTS | g++-4.9 (Ubuntu 4.9.4-2ubuntu1~16.04) 4.9.4 |
| GCC 5.5.0 | Ubuntu 16.04.5 LTS | g++-5 (Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010 |
| GCC 6.5.0 | Ubuntu 16.04.5 LTS | g++-6 (Ubuntu 6.5.0-2ubuntu1~16.04) 6.5.0 20181026 |
| GCC 7.4.0 | Ubuntu 16.04.5 LTS | g++-7 (Ubuntu 7.4.0-1ubuntu1\~16.04\~ppa1) 7.4.0 |
| GCC 8.1.0 | Ubuntu 16.04.5 LTS | g++-8 (Ubuntu 8.1.0-5ubuntu1~16.04) 8.1.0 |
| Clang 3.6.2 | Ubuntu 16.04.5 LTS | Ubuntu clang version 3.6.2-3ubuntu2 (tags/RELEASE_362/final) (based on LLVM 3.6.2) |
| Clang 3.7.1 | Ubuntu 16.04.5 LTS | Ubuntu clang version 3.7.1-2ubuntu2 (tags/RELEASE_371/final) (based on LLVM 3.7.1) |
| Clang 3.8.0 | Ubuntu 16.04.5 LTS | clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final) |
| Clang 3.9.1 | Ubuntu 16.04.5 LTS | clang version 3.9.1-4ubuntu3~16.04.2 (tags/RELEASE_391/rc2) |
| Clang 4.0.0 | Ubuntu 16.04.5 LTS | clang version 4.0.0-1ubuntu1~16.04.2 (tags/RELEASE_400/rc1) |
| Clang 5.0.0 | Ubuntu 16.04.5 LTS | clang version 5.0.0-3~16.04.1 (tags/RELEASE_500/final) |
| Clang 6.0.0 | Ubuntu 16.04.5 LTS | clang version 6.0.0-1ubuntu2~16.04.1 (tags/RELEASE_600/final) |
| Clang 7.0.1 | Ubuntu 16.04.5 LTS | clang version 7.0.1-svn347285-1\~exp1\~20181124105320.40 (branches/release_70) |
| Clang Xcode 7.3 | Darwin Kernel Version 15.6.0 (OS X 10.11.6) | Apple LLVM version 7.3.0 (clang-703.0.31) |
| Clang Xcode 8.3 | Darwin Kernel Version 16.6.0 (OS X 10.12.5) | Apple LLVM version 8.1.0 (clang-802.0.42) |
| Clang Xcode 9.4 | Darwin Kernel Version 17.4.0 (OS X 10.13.3) | Apple LLVM version 9.1.0 (clang-902.0.39.2) |
| Clang Xcode 10.1 | Darwin Kernel Version 17.7.0 (OS X 10.13.6) | Apple LLVM version 10.0.0 (clang-1000.11.45.5) |
| Visual Studio 14 2015 | Visual Studio 2015 with Update 3 | MSVC 19.0.24241.7 |
| Visual Studio 15 2017 | Visual Studio 2017 with Update 8 | MSVC 19.15.26732.1 |
| Visual Studio 15 2017 | Visual Studio 2017 with Update 9 | MSVC 19.16.27025.1 |
| Visual Studio 15 2017 (__Clang/LLVM__) | Visual Studio 2017 | Clang 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](test/README.md).
## License
Distributed under the [Boost Software License, Version 1.0](LICENSE.md).

View File

@ -1,26 +0,0 @@
# MPark.Variant
#
# Copyright Michael Park, 2015-2017
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
# Config file for MPark.Variant
#
# `MPARK_VARIANT_INCLUDE_DIRS` - include directories
# `MPARK_VARIANT_LIBRARIES` - libraries to link against
#
# The following `IMPORTED` target is also defined:
#
# `mpark_variant`
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/mpark_variant-targets.cmake")
get_target_property(
MPARK_VARIANT_INCLUDE_DIRS
mpark_variant INTERFACE_INCLUDE_DIRECTORIES)
set_and_check(MPARK_VARIANT_INCLUDE_DIRS "${MPARK_VARIANT_INCLUDE_DIRS}")
set(MPARK_VARIANT_LIBRARIES mpark_variant)

View File

@ -1,96 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#ifndef MPARK_CONFIG_HPP
#define MPARK_CONFIG_HPP
// MSVC 2015 Update 3.
#if __cplusplus < 201103L && (!defined(_MSC_VER) || _MSC_FULL_VER < 190024210)
#error "MPark.Variant requires C++11 support."
#endif
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#ifndef __has_include
#define __has_include(x) 0
#endif
#ifndef __has_feature
#define __has_feature(x) 0
#endif
#if __has_attribute(always_inline) || defined(__GNUC__)
#define MPARK_ALWAYS_INLINE __attribute__((__always_inline__)) inline
#elif defined(_MSC_VER)
#define MPARK_ALWAYS_INLINE __forceinline
#else
#define MPARK_ALWAYS_INLINE inline
#endif
#if __has_builtin(__builtin_addressof) || \
(defined(__GNUC__) && __GNUC__ >= 7) || defined(_MSC_VER)
#define MPARK_BUILTIN_ADDRESSOF
#endif
#if __has_builtin(__builtin_unreachable) || defined(__GNUC__)
#define MPARK_BUILTIN_UNREACHABLE __builtin_unreachable()
#elif defined(_MSC_VER)
#define MPARK_BUILTIN_UNREACHABLE __assume(false)
#else
#define MPARK_BUILTIN_UNREACHABLE
#endif
#if __has_builtin(__type_pack_element)
#define MPARK_TYPE_PACK_ELEMENT
#endif
#if defined(__cpp_constexpr) && __cpp_constexpr >= 200704 && \
!(defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 9)
#define MPARK_CPP11_CONSTEXPR
#endif
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304
#define MPARK_CPP14_CONSTEXPR
#endif
#if __has_feature(cxx_exceptions) || defined(__cpp_exceptions) || \
(defined(_MSC_VER) && defined(_CPPUNWIND))
#define MPARK_EXCEPTIONS
#endif
#if defined(__cpp_generic_lambdas) || defined(_MSC_VER)
#define MPARK_GENERIC_LAMBDAS
#endif
#if defined(__cpp_lib_integer_sequence)
#define MPARK_INTEGER_SEQUENCE
#endif
#if defined(__cpp_return_type_deduction) || defined(_MSC_VER)
#define MPARK_RETURN_TYPE_DEDUCTION
#endif
#if defined(__cpp_lib_transparent_operators) || defined(_MSC_VER)
#define MPARK_TRANSPARENT_OPERATORS
#endif
#if defined(__cpp_variable_templates) || defined(_MSC_VER)
#define MPARK_VARIABLE_TEMPLATES
#endif
#if !defined(__GLIBCXX__) || __has_include(<codecvt>) // >= libstdc++-5
#define MPARK_TRIVIALITY_TYPE_TRAITS
#define MPARK_INCOMPLETE_TYPE_TRAITS
#endif
#endif // MPARK_CONFIG_HPP

View File

@ -1,35 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#ifndef MPARK_IN_PLACE_HPP
#define MPARK_IN_PLACE_HPP
#include <cstddef>
#include "config.hpp"
namespace mpark {
struct in_place_t { explicit in_place_t() = default; };
template <std::size_t I>
struct in_place_index_t { explicit in_place_index_t() = default; };
template <typename T>
struct in_place_type_t { explicit in_place_type_t() = default; };
#ifdef MPARK_VARIABLE_TEMPLATES
constexpr in_place_t in_place{};
template <std::size_t I> constexpr in_place_index_t<I> in_place_index{};
template <typename T> constexpr in_place_type_t<T> in_place_type{};
#endif
} // namespace mpark
#endif // MPARK_IN_PLACE_HPP

View File

@ -1,537 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#ifndef MPARK_LIB_HPP
#define MPARK_LIB_HPP
#include <memory>
#include <functional>
#include <type_traits>
#include <utility>
#include "config.hpp"
#define MPARK_RETURN(...) \
noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) { return __VA_ARGS__; }
namespace mpark {
namespace lib {
template <typename T>
struct identity { using type = T; };
inline namespace cpp14 {
template <typename T, std::size_t N>
struct array {
constexpr const T &operator[](std::size_t index) const {
return data[index];
}
T data[N == 0 ? 1 : N];
};
template <typename T>
using add_pointer_t = typename std::add_pointer<T>::type;
template <typename... Ts>
using common_type_t = typename std::common_type<Ts...>::type;
template <typename T>
using decay_t = typename std::decay<T>::type;
template <bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type;
template <typename T>
using remove_const_t = typename std::remove_const<T>::type;
template <typename T>
using remove_reference_t = typename std::remove_reference<T>::type;
template <typename T>
inline constexpr T &&forward(remove_reference_t<T> &t) noexcept {
return static_cast<T &&>(t);
}
template <typename T>
inline constexpr T &&forward(remove_reference_t<T> &&t) noexcept {
static_assert(!std::is_lvalue_reference<T>::value,
"can not forward an rvalue as an lvalue");
return static_cast<T &&>(t);
}
template <typename T>
inline constexpr remove_reference_t<T> &&move(T &&t) noexcept {
return static_cast<remove_reference_t<T> &&>(t);
}
#ifdef MPARK_INTEGER_SEQUENCE
using std::integer_sequence;
using std::index_sequence;
using std::make_index_sequence;
using std::index_sequence_for;
#else
template <typename T, T... Is>
struct integer_sequence {
using value_type = T;
static constexpr std::size_t size() noexcept { return sizeof...(Is); }
};
template <std::size_t... Is>
using index_sequence = integer_sequence<std::size_t, Is...>;
template <typename Lhs, typename Rhs>
struct make_index_sequence_concat;
template <std::size_t... Lhs, std::size_t... Rhs>
struct make_index_sequence_concat<index_sequence<Lhs...>,
index_sequence<Rhs...>>
: identity<index_sequence<Lhs..., (sizeof...(Lhs) + Rhs)...>> {};
template <std::size_t N>
struct make_index_sequence_impl;
template <std::size_t N>
using make_index_sequence = typename make_index_sequence_impl<N>::type;
template <std::size_t N>
struct make_index_sequence_impl
: make_index_sequence_concat<make_index_sequence<N / 2>,
make_index_sequence<N - (N / 2)>> {};
template <>
struct make_index_sequence_impl<0> : identity<index_sequence<>> {};
template <>
struct make_index_sequence_impl<1> : identity<index_sequence<0>> {};
template <typename... Ts>
using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
#endif
// <functional>
#ifdef MPARK_TRANSPARENT_OPERATORS
using equal_to = std::equal_to<>;
#else
struct equal_to {
template <typename Lhs, typename Rhs>
inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
MPARK_RETURN(lib::forward<Lhs>(lhs) == lib::forward<Rhs>(rhs))
};
#endif
#ifdef MPARK_TRANSPARENT_OPERATORS
using not_equal_to = std::not_equal_to<>;
#else
struct not_equal_to {
template <typename Lhs, typename Rhs>
inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
MPARK_RETURN(lib::forward<Lhs>(lhs) != lib::forward<Rhs>(rhs))
};
#endif
#ifdef MPARK_TRANSPARENT_OPERATORS
using less = std::less<>;
#else
struct less {
template <typename Lhs, typename Rhs>
inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
MPARK_RETURN(lib::forward<Lhs>(lhs) < lib::forward<Rhs>(rhs))
};
#endif
#ifdef MPARK_TRANSPARENT_OPERATORS
using greater = std::greater<>;
#else
struct greater {
template <typename Lhs, typename Rhs>
inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
MPARK_RETURN(lib::forward<Lhs>(lhs) > lib::forward<Rhs>(rhs))
};
#endif
#ifdef MPARK_TRANSPARENT_OPERATORS
using less_equal = std::less_equal<>;
#else
struct less_equal {
template <typename Lhs, typename Rhs>
inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
MPARK_RETURN(lib::forward<Lhs>(lhs) <= lib::forward<Rhs>(rhs))
};
#endif
#ifdef MPARK_TRANSPARENT_OPERATORS
using greater_equal = std::greater_equal<>;
#else
struct greater_equal {
template <typename Lhs, typename Rhs>
inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
MPARK_RETURN(lib::forward<Lhs>(lhs) >= lib::forward<Rhs>(rhs))
};
#endif
} // namespace cpp14
inline namespace cpp17 {
// <type_traits>
template <bool B>
using bool_constant = std::integral_constant<bool, B>;
template <typename...>
struct voider : identity<void> {};
template <typename... Ts>
using void_t = typename voider<Ts...>::type;
namespace detail {
namespace swappable {
using std::swap;
template <typename T>
struct is_swappable {
private:
template <typename U,
typename = decltype(swap(std::declval<U &>(),
std::declval<U &>()))>
inline static std::true_type test(int);
template <typename U>
inline static std::false_type test(...);
public:
static constexpr bool value = decltype(test<T>(0))::value;
};
template <bool IsSwappable, typename T>
struct is_nothrow_swappable {
static constexpr bool value =
noexcept(swap(std::declval<T &>(), std::declval<T &>()));
};
template <typename T>
struct is_nothrow_swappable<false, T> : std::false_type {};
} // namespace swappable
} // namespace detail
using detail::swappable::is_swappable;
template <typename T>
using is_nothrow_swappable =
detail::swappable::is_nothrow_swappable<is_swappable<T>::value, T>;
// <functional>
namespace detail {
template <typename T>
struct is_reference_wrapper : std::false_type {};
template <typename T>
struct is_reference_wrapper<std::reference_wrapper<T>>
: std::true_type {};
template <bool, int>
struct Invoke;
template <>
struct Invoke<true /* pmf */, 0 /* is_base_of */> {
template <typename R, typename T, typename Arg, typename... Args>
inline static constexpr auto invoke(R T::*pmf, Arg &&arg, Args &&... args)
MPARK_RETURN((lib::forward<Arg>(arg).*pmf)(lib::forward<Args>(args)...))
};
template <>
struct Invoke<true /* pmf */, 1 /* is_reference_wrapper */> {
template <typename R, typename T, typename Arg, typename... Args>
inline static constexpr auto invoke(R T::*pmf, Arg &&arg, Args &&... args)
MPARK_RETURN((lib::forward<Arg>(arg).get().*pmf)(lib::forward<Args>(args)...))
};
template <>
struct Invoke<true /* pmf */, 2 /* otherwise */> {
template <typename R, typename T, typename Arg, typename... Args>
inline static constexpr auto invoke(R T::*pmf, Arg &&arg, Args &&... args)
MPARK_RETURN(((*lib::forward<Arg>(arg)).*pmf)(lib::forward<Args>(args)...))
};
template <>
struct Invoke<false /* pmo */, 0 /* is_base_of */> {
template <typename R, typename T, typename Arg>
inline static constexpr auto invoke(R T::*pmo, Arg &&arg)
MPARK_RETURN(lib::forward<Arg>(arg).*pmo)
};
template <>
struct Invoke<false /* pmo */, 1 /* is_reference_wrapper */> {
template <typename R, typename T, typename Arg>
inline static constexpr auto invoke(R T::*pmo, Arg &&arg)
MPARK_RETURN(lib::forward<Arg>(arg).get().*pmo)
};
template <>
struct Invoke<false /* pmo */, 2 /* otherwise */> {
template <typename R, typename T, typename Arg>
inline static constexpr auto invoke(R T::*pmo, Arg &&arg)
MPARK_RETURN((*lib::forward<Arg>(arg)).*pmo)
};
template <typename R, typename T, typename Arg, typename... Args>
inline constexpr auto invoke(R T::*f, Arg &&arg, Args &&... args)
MPARK_RETURN(
Invoke<std::is_function<R>::value,
(std::is_base_of<T, lib::decay_t<Arg>>::value
? 0
: is_reference_wrapper<lib::decay_t<Arg>>::value
? 1
: 2)>::invoke(f,
lib::forward<Arg>(arg),
lib::forward<Args>(args)...))
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4100)
#endif
template <typename F, typename... Args>
inline constexpr auto invoke(F &&f, Args &&... args)
MPARK_RETURN(lib::forward<F>(f)(lib::forward<Args>(args)...))
#ifdef _MSC_VER
#pragma warning(pop)
#endif
} // namespace detail
template <typename F, typename... Args>
inline constexpr auto invoke(F &&f, Args &&... args)
MPARK_RETURN(detail::invoke(lib::forward<F>(f),
lib::forward<Args>(args)...))
namespace detail {
template <typename Void, typename, typename...>
struct invoke_result {};
template <typename F, typename... Args>
struct invoke_result<void_t<decltype(lib::invoke(
std::declval<F>(), std::declval<Args>()...))>,
F,
Args...>
: identity<decltype(
lib::invoke(std::declval<F>(), std::declval<Args>()...))> {};
} // namespace detail
template <typename F, typename... Args>
using invoke_result = detail::invoke_result<void, F, Args...>;
template <typename F, typename... Args>
using invoke_result_t = typename invoke_result<F, Args...>::type;
namespace detail {
template <typename Void, typename, typename...>
struct is_invocable : std::false_type {};
template <typename F, typename... Args>
struct is_invocable<void_t<invoke_result_t<F, Args...>>, F, Args...>
: std::true_type {};
template <typename Void, typename, typename, typename...>
struct is_invocable_r : std::false_type {};
template <typename R, typename F, typename... Args>
struct is_invocable_r<void_t<invoke_result_t<F, Args...>>,
R,
F,
Args...>
: std::is_convertible<invoke_result_t<F, Args...>, R> {};
} // namespace detail
template <typename F, typename... Args>
using is_invocable = detail::is_invocable<void, F, Args...>;
template <typename R, typename F, typename... Args>
using is_invocable_r = detail::is_invocable_r<void, R, F, Args...>;
namespace detail {
template <bool Invocable, typename F, typename... Args>
struct is_nothrow_invocable {
static constexpr bool value =
noexcept(lib::invoke(std::declval<F>(), std::declval<Args>()...));
};
template <typename F, typename... Args>
struct is_nothrow_invocable<false, F, Args...> : std::false_type {};
template <bool Invocable, typename R, typename F, typename... Args>
struct is_nothrow_invocable_r {
private:
inline static R impl() {
return lib::invoke(std::declval<F>(), std::declval<Args>()...);
}
public:
static constexpr bool value = noexcept(impl());
};
template <typename R, typename F, typename... Args>
struct is_nothrow_invocable_r<false, R, F, Args...> : std::false_type {};
} // namespace detail
template <typename F, typename... Args>
using is_nothrow_invocable = detail::
is_nothrow_invocable<is_invocable<F, Args...>::value, F, Args...>;
template <typename R, typename F, typename... Args>
using is_nothrow_invocable_r =
detail::is_nothrow_invocable_r<is_invocable_r<R, F, Args...>::value,
R,
F,
Args...>;
// <memory>
#ifdef MPARK_BUILTIN_ADDRESSOF
template <typename T>
inline constexpr T *addressof(T &arg) noexcept {
return __builtin_addressof(arg);
}
#else
namespace detail {
namespace has_addressof_impl {
struct fail;
template <typename T>
inline fail operator&(T &&);
template <typename T>
inline static constexpr bool impl() {
return (std::is_class<T>::value || std::is_union<T>::value) &&
!std::is_same<decltype(&std::declval<T &>()), fail>::value;
}
} // namespace has_addressof_impl
template <typename T>
using has_addressof = bool_constant<has_addressof_impl::impl<T>()>;
template <typename T>
inline constexpr T *addressof(T &arg, std::true_type) noexcept {
return std::addressof(arg);
}
template <typename T>
inline constexpr T *addressof(T &arg, std::false_type) noexcept {
return &arg;
}
} // namespace detail
template <typename T>
inline constexpr T *addressof(T &arg) noexcept {
return detail::addressof(arg, detail::has_addressof<T>{});
}
#endif
template <typename T>
inline constexpr T *addressof(const T &&) = delete;
} // namespace cpp17
template <typename T>
struct remove_all_extents : identity<T> {};
template <typename T, std::size_t N>
struct remove_all_extents<array<T, N>> : remove_all_extents<T> {};
template <typename T>
using remove_all_extents_t = typename remove_all_extents<T>::type;
template <std::size_t N>
using size_constant = std::integral_constant<std::size_t, N>;
template <std::size_t I, typename T>
struct indexed_type : size_constant<I> { using type = T; };
template <bool... Bs>
using all = std::is_same<integer_sequence<bool, true, Bs...>,
integer_sequence<bool, Bs..., true>>;
#ifdef MPARK_TYPE_PACK_ELEMENT
template <std::size_t I, typename... Ts>
using type_pack_element_t = __type_pack_element<I, Ts...>;
#else
template <std::size_t I, typename... Ts>
struct type_pack_element_impl {
private:
template <typename>
struct set;
template <std::size_t... Is>
struct set<index_sequence<Is...>> : indexed_type<Is, Ts>... {};
template <typename T>
inline static std::enable_if<true, T> impl(indexed_type<I, T>);
inline static std::enable_if<false> impl(...);
public:
using type = decltype(impl(set<index_sequence_for<Ts...>>{}));
};
template <std::size_t I, typename... Ts>
using type_pack_element = typename type_pack_element_impl<I, Ts...>::type;
template <std::size_t I, typename... Ts>
using type_pack_element_t = typename type_pack_element<I, Ts...>::type;
#endif
#ifdef MPARK_TRIVIALITY_TYPE_TRAITS
using std::is_trivially_copy_constructible;
using std::is_trivially_move_constructible;
using std::is_trivially_copy_assignable;
using std::is_trivially_move_assignable;
#else
template <typename T>
struct is_trivially_copy_constructible
: bool_constant<
std::is_copy_constructible<T>::value && __has_trivial_copy(T)> {};
template <typename T>
struct is_trivially_move_constructible : bool_constant<__is_trivial(T)> {};
template <typename T>
struct is_trivially_copy_assignable
: bool_constant<
std::is_copy_assignable<T>::value && __has_trivial_assign(T)> {};
template <typename T>
struct is_trivially_move_assignable : bool_constant<__is_trivial(T)> {};
#endif
template <typename T, bool>
struct dependent_type : T {};
template <typename Is, std::size_t J>
struct push_back;
template <typename Is, std::size_t J>
using push_back_t = typename push_back<Is, J>::type;
template <std::size_t... Is, std::size_t J>
struct push_back<index_sequence<Is...>, J> {
using type = index_sequence<Is..., J>;
};
} // namespace lib
} // namespace mpark
#undef MPARK_RETURN
#endif // MPARK_LIB_HPP

File diff suppressed because it is too large Load Diff

View File

@ -1,46 +0,0 @@
# MPark.Variant
#
# Copyright Michael Park, 2015-2017
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
import os
import pprint
import subprocess
result = {}
std_flags = os.getenv('STDFLAGS')
for std_flag in std_flags.split() if std_flags is not None else ['']:
os.environ['CXXFLAGS'] = std_flag
for exceptions in ['OFF', 'ON']:
for build_type in ['Debug', 'Release']:
config = '{}-{}-{}'.format(
filter(str.isalnum, std_flag), exceptions, build_type)
build_dir = 'build-{}'.format(config)
os.mkdir(build_dir)
os.chdir(build_dir)
result[config] = { 'Configure': None, 'Build': None, 'Test': None }
tests = os.environ['TESTS'].split()
if std_flag.endswith(('11', '1y', '14', '1z')) and 'libc++' in tests:
tests.remove('libc++')
result[config]['Configure'] = subprocess.call([
'cmake', '-GNinja',
'-DCMAKE_BUILD_TYPE={}'.format(build_type),
'-DMPARK_VARIANT_EXCEPTIONS={}'.format(exceptions),
'-DMPARK_VARIANT_INCLUDE_TESTS={}'.format(';'.join(tests)),
'..',
])
if result[config]['Configure'] == 0:
result[config]['Build'] = subprocess.call([
'cmake', '--build', '.', '--', '-k', '0'])
if result[config]['Build'] == 0:
result[config]['Test'] = subprocess.call([
'ctest', '--output-on-failure'])
os.chdir('..')
pprint.pprint(result)
exit(any(status != 0 for d in result.itervalues() for status in d.itervalues()))

View File

@ -1,39 +0,0 @@
#! /usr/bin/env python
# MPark.Variant
#
# Copyright Michael Park, 2017
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
import os.path
import re
import subprocess
import sys
# Prints a single header version of `include/mpark/variant.hpp` to stdout.
processed = []
def process(header):
result = ''
with open(header, 'r') as f:
for line in f:
p = re.compile('^#include "(.+)"')
m = p.match(line)
if m is None:
result += line
else:
g = m.group(1)
include = os.path.normpath(os.path.join(os.path.dirname(header), g))
if include not in processed:
result += process(include)
result += '\n'
processed.append(include)
return result
root = subprocess.check_output(['git', 'rev-parse', '--show-toplevel']).strip()
result = process(os.path.join(root, 'include/mpark/variant.hpp'))
sys.stdout.write(result)

View File

@ -1,51 +0,0 @@
# MPark.Variant
#
# Copyright Michael Park, 2015-2017
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
import os
import pprint
import subprocess
result = {}
std_flags = os.getenv('STDFLAGS')
for std_flag in std_flags.split() if std_flags is not None else ['']:
os.environ['CXXFLAGS'] = std_flag
for exceptions in ['OFF', 'ON']:
config = '{}-{}'.format(filter(str.isalnum, std_flag), exceptions)
build_dir = 'build-{}'.format(config)
os.mkdir(build_dir)
os.chdir(build_dir)
result[config] = {
'Configure': None,
'Build-Debug': None,
'Build-Release': None,
'Test-Debug': None,
'Test-Release': None
}
tests = os.environ['TESTS'].split()
if std_flag.endswith(('11', '1y', '14', '1z')) and 'libc++' in tests:
tests.remove('libc++')
configure = [
'cmake', '-G', os.environ['GENERATOR'],
'-DMPARK_VARIANT_EXCEPTIONS={}'.format(exceptions),
'-DMPARK_VARIANT_INCLUDE_TESTS={}'.format(';'.join(tests)),
'..',
]
result[config]['Configure'] = subprocess.call(configure)
if result[config]['Configure'] == 0:
for build_type in ['Debug', 'Release']:
result[config]['Build-{}'.format(build_type)] = subprocess.call([
'cmake', '--build', '.', '--config', build_type])
if result[config]['Build-{}'.format(build_type)] == 0:
result[config]['Test-{}'.format(build_type)] = subprocess.call([
'ctest', '--output-on-failure', '--build-config', build_type])
os.chdir('..')
pprint.pprint(result)
exit(any(status != 0 for d in result.itervalues() for status in d.itervalues()))

View File

@ -1,19 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <iostream>
#include <string>
#include <vector>
#include <mpark/variant.hpp>
int main() {
std::vector<mpark::variant<int, std::string>> vs = { 101, "+", 202, "==", 303 };
for (const auto& v : vs) {
mpark::visit([](const auto& x) { std::cout << x << ' '; }, v);
}
}

View File

@ -1,106 +0,0 @@
#! /usr/bin/env python
# MPark.Variant
#
# This script uploads a directory to Wandbox (http://melpon.org/wandbox),
# which is an online compiler environment, and prints a permalink to the
# uploaded code. We use this to provide a "Try it online" version of the
# library to make the barrier to entry as low as possible.
#
# This script was adapted from the script proposed in
# https://github.com/melpon/wandbox/issues/153.
#
# To know how to use this script: ./wandbox.py --help
#
# Copyright Louis Dionne 2015
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#
# Copyright Michael Park, 2017
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
import argparse
import fnmatch
import json
import os
import re
import urllib2
# Post the given JSON data to Wandbox's API, and return the result
# as a JSON object.
def upload(options):
request = urllib2.Request('http://melpon.org/wandbox/api/compile.json')
request.add_header('Content-Type', 'application/json')
response = urllib2.urlopen(request, json.dumps(options))
return json.loads(response.read())
# Returns a list of the '.hpp' headers in the given directory and in
# subdirectories.
#
# The path must be absolute, and the returned paths are all absolute too.
def headers(path):
return [
os.path.join(dir, file)
for (dir, _, files) in os.walk(path)
for file in fnmatch.filter(files, "*.hpp")
]
def main():
parser = argparse.ArgumentParser(description=
"""Upload a directory to Wandbox (http://melpon.org/wandbox).
On success, the program prints a permalink to the uploaded
directory on Wandbox and returns 0. On error, it prints the
response from the Wandbox API and returns 1.
Note that the comments are stripped from all the headers in the
uploaded directory.
"""
)
parser.add_argument('directory', type=str, help=
"""A directory to upload to Wandbox.
The path may be either absolute or relative to the current directory.
However, the names of the files uploaded to Wandbox will all be
relative to this directory. This way, one can easily specify the
directory to be '/some/project/include', and the uploaded files
will be uploaded as-if they were rooted at '/some/project/include'
""")
parser.add_argument('main', type=str, help=
"""The main source file.
The path may be either absolute or relative to the current directory.
"""
)
args = parser.parse_args()
directory = os.path.abspath(args.directory)
if not os.path.exists(directory):
raise Exception("'%s' is not a valid directory" % args.directory)
cpp = os.path.abspath(args.main)
if not os.path.exists(cpp):
raise Exception("'%s' is not a valid file name" % args.main)
response = upload({
'code': open(cpp).read().strip(),
'codes': [{
'file': os.path.relpath(header, directory).replace('\\', '/'),
'code': open(header).read().strip()
} for header in headers(directory)],
'options': 'warning,optimize,c++14',
'compiler': 'clang-4.0.0',
'save': True,
'compiler-option-raw': '-I.'
})
if response['status'] == '0':
print response['url']
return 0
else:
print response
return 1
exit(main())

View File

@ -1,49 +0,0 @@
# MPark.Variant
> __C++17__ `std::variant` for __C++11__/__14__/__17__
[![release][badge.release]][release]
[![header][badge.header]][header]
[![travis][badge.travis]][travis]
[![appveyor][badge.appveyor]][appveyor]
[![license][badge.license]][license]
[![godbolt][badge.godbolt]][godbolt]
[![wandbox][badge.wandbox]][wandbox]
[badge.release]: https://img.shields.io/github/release/mpark/variant.svg
[badge.header]: https://img.shields.io/badge/single%20header-master-blue.svg
[badge.travis]: https://travis-ci.org/mpark/variant.svg?branch=master
[badge.appveyor]: https://ci.appveyor.com/api/projects/status/github/mpark/variant?branch=master&svg=true
[badge.license]: https://img.shields.io/badge/license-boost-blue.svg
[badge.godbolt]: https://img.shields.io/badge/try%20it-on%20godbolt-222266.svg
[badge.wandbox]: https://img.shields.io/badge/try%20it-on%20wandbox-5cb85c.svg
[release]: https://github.com/mpark/variant/releases/latest
[header]: https://github.com/mpark/variant/blob/single-header/master/variant.hpp
[travis]: https://travis-ci.org/mpark/variant
[appveyor]: https://ci.appveyor.com/project/mpark/variant
[license]: https://github.com/mpark/variant/blob/master/LICENSE.md
[godbolt]: https://godbolt.org/g/1qYDAK
[wandbox]: https://wandbox.org/permlink/QV3gZ2KQQNwgoFIB
## Test
This directory contains the tests for __MPark.Variant__.
## CMake Variables
- __`MPARK_VARIANT_EXCEPTIONS`__:`BOOL` (__default__: `ON`)
Build the tests with exceptions support.
## Build / Run
Execute the following commands from the top-level directory:
```bash
mkdir build
cd build
cmake -DMPARK_VARIANT_INCLUDE_TESTS="mpark;libc++" ..
cmake --build .
ctest --output-on-failure
```

View File

@ -1,51 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <gtest/gtest.h>
#include "util.hpp"
TEST(Assign_Copy, SameType) {
struct Obj {
constexpr Obj() {}
Obj(const Obj &) noexcept { EXPECT_TRUE(false); }
Obj(Obj &&) = default;
Obj &operator=(const Obj &) noexcept { EXPECT_TRUE(true); return *this; }
Obj &operator=(Obj &&) = delete;
};
// `v`, `w`.
mpark::variant<Obj, int> v, w;
// copy assignment.
v = w;
}
TEST(Assign_Copy, DiffType) {
struct Obj {
constexpr Obj() {}
Obj(const Obj &) noexcept { EXPECT_TRUE(true); }
Obj(Obj &&) = default;
Obj &operator=(const Obj &) noexcept { EXPECT_TRUE(false); return *this; }
Obj &operator=(Obj &&) = delete;
};
// `v`, `w`.
mpark::variant<Obj, int> v(42), w;
// copy assignment.
v = w;
}
#ifdef MPARK_EXCEPTIONS
TEST(Assign_Copy, ValuelessByException) {
mpark::variant<int, move_thrower_t> v(42);
EXPECT_THROW(v = move_thrower_t{}, MoveConstruction);
EXPECT_TRUE(v.valueless_by_exception());
mpark::variant<int, move_thrower_t> w(42);
w = v;
EXPECT_TRUE(w.valueless_by_exception());
}
#endif

View File

@ -1,134 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <sstream>
#include <string>
#include <type_traits>
#include <gtest/gtest.h>
#include "util.hpp"
TEST(Assign_Fwd, SameType) {
mpark::variant<int, std::string> v(101);
EXPECT_EQ(101, mpark::get<int>(v));
v = 202;
EXPECT_EQ(202, mpark::get<int>(v));
}
TEST(Assign_Fwd, SameTypeFwd) {
mpark::variant<int, std::string> v(1.1);
EXPECT_EQ(1, mpark::get<int>(v));
v = 2.2;
EXPECT_EQ(2, mpark::get<int>(v));
}
TEST(Assign_Fwd, DiffType) {
mpark::variant<int, std::string> v(42);
EXPECT_EQ(42, mpark::get<int>(v));
v = "42";
EXPECT_EQ("42", mpark::get<std::string>(v));
}
TEST(Assign_Fwd, DiffTypeFwd) {
mpark::variant<int, std::string> v(42);
EXPECT_EQ(42, mpark::get<int>(v));
v = "42";
EXPECT_EQ("42", mpark::get<std::string>(v));
}
TEST(Assign_Fwd, ExactMatch) {
mpark::variant<const char *, std::string> v;
v = std::string("hello");
EXPECT_EQ("hello", mpark::get<std::string>(v));
}
TEST(Assign_Fwd, BetterMatch) {
mpark::variant<int, double> v;
// `char` -> `int` is better than `char` -> `double`
v = 'x';
EXPECT_EQ(static_cast<int>('x'), mpark::get<int>(v));
}
TEST(Assign_Fwd, NoMatch) {
struct x {};
static_assert(!std::is_assignable<mpark::variant<int, std::string>, x>{},
"variant<int, std::string> v; v = x;");
}
TEST(Assign_Fwd, Ambiguous) {
static_assert(!std::is_assignable<mpark::variant<short, long>, int>{},
"variant<short, long> v; v = 42;");
}
TEST(Assign_Fwd, SameTypeOptimization) {
mpark::variant<int, std::string> v("hello world!");
// Check `v`.
const std::string &x = mpark::get<std::string>(v);
EXPECT_EQ("hello world!", x);
// Save the "hello world!"'s capacity.
auto capacity = x.capacity();
// Use `std::string::operator=(const char *)` to assign into `v`.
v = "hello";
// Check `v`.
const std::string &y = mpark::get<std::string>(v);
EXPECT_EQ("hello", y);
// Since "hello" is shorter than "hello world!", we should have preserved the
// existing capacity of the string!.
EXPECT_EQ(capacity, y.capacity());
}
#ifdef MPARK_EXCEPTIONS
TEST(Assign_Fwd, ThrowOnAssignment) {
mpark::variant<int, move_thrower_t> v(
mpark::in_place_type_t<move_thrower_t>{});
// Since `variant` is already in `move_thrower_t`, assignment optimization
// kicks and we simply invoke
// `move_thrower_t &operator=(move_thrower_t &&);` which throws.
EXPECT_THROW(v = move_thrower_t{}, MoveAssignment);
EXPECT_FALSE(v.valueless_by_exception());
EXPECT_EQ(1u, v.index());
// We can still assign into a variant in an invalid state.
v = 42;
// Check `v`.
EXPECT_FALSE(v.valueless_by_exception());
EXPECT_EQ(42, mpark::get<int>(v));
}
#endif
#if 0
TEST(Assign_Fwd, ThrowOnTemporaryConstruction) {
mpark::variant<int, copy_thrower_t> v(42);
// Since `copy_thrower_t`'s copy constructor always throws, we will fail to
// construct the variant. This results in our variant staying in
// its original state.
copy_thrower_t copy_thrower{};
EXPECT_THROW(v = copy_thrower, CopyConstruction);
EXPECT_FALSE(v.valueless_by_exception());
EXPECT_EQ(0u, v.index());
EXPECT_EQ(42, mpark::get<int>(v));
}
TEST(Assign_Fwd, ThrowOnVariantConstruction) {
mpark::variant<int, move_thrower_t> v(42);
// Since `move_thrower_t`'s copy constructor never throws, we successfully
// construct the temporary object by copying `move_thrower_t`. We then
// proceed to move the temporary object into our variant, at which point
// `move_thrower_t`'s move constructor throws. This results in our `variant`
// transitioning into the invalid state.
move_thrower_t move_thrower;
EXPECT_THROW(v = move_thrower, MoveConstruction);
EXPECT_TRUE(v.valueless_by_exception());
// We can still assign into a variant in an invalid state.
v = 42;
// Check `v`.
EXPECT_FALSE(v.valueless_by_exception());
EXPECT_EQ(42, mpark::get<int>(v));
}
#endif

View File

@ -1,53 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <gtest/gtest.h>
#include "util.hpp"
namespace lib = mpark::lib;
TEST(Assign_Move, SameType) {
struct Obj {
constexpr Obj() {}
Obj(const Obj &) = delete;
Obj(Obj &&) noexcept { EXPECT_TRUE(false); }
Obj &operator=(const Obj &) = delete;
Obj &operator=(Obj &&) noexcept { EXPECT_TRUE(true); return *this; }
};
// `v`, `w`.
mpark::variant<Obj, int> v, w;
// move assignment.
v = lib::move(w);
}
TEST(Assign_Move, DiffType) {
struct Obj {
constexpr Obj() {}
Obj(const Obj &) = delete;
Obj(Obj &&) noexcept { EXPECT_TRUE(true); }
Obj &operator=(const Obj &) = delete;
Obj &operator=(Obj &&) noexcept { EXPECT_TRUE(false); return *this; }
};
// `v`, `w`.
mpark::variant<Obj, int> v(42), w;
// move assignment.
v = lib::move(w);
}
#ifdef MPARK_EXCEPTIONS
TEST(Assign_Move, ValuelessByException) {
mpark::variant<int, move_thrower_t> v(42);
EXPECT_THROW(v = move_thrower_t{}, MoveConstruction);
EXPECT_TRUE(v.valueless_by_exception());
mpark::variant<int, move_thrower_t> w(42);
w = lib::move(v);
EXPECT_TRUE(w.valueless_by_exception());
}
#endif

View File

@ -1,44 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <string>
#include <gtest/gtest.h>
#include "util.hpp"
TEST(Ctor_Copy, Value) {
// `v`
mpark::variant<int, std::string> v("hello");
EXPECT_EQ("hello", mpark::get<std::string>(v));
// `w`
mpark::variant<int, std::string> w(v);
EXPECT_EQ("hello", mpark::get<std::string>(w));
// Check `v`
EXPECT_EQ("hello", mpark::get<std::string>(v));
/* constexpr */ {
// `cv`
constexpr mpark::variant<int, const char *> cv(42);
static_assert(42 == mpark::get<int>(cv), "");
// `cw`
constexpr mpark::variant<int, const char *> cw(cv);
static_assert(42 == mpark::get<int>(cw), "");
}
}
#ifdef MPARK_EXCEPTIONS
TEST(Ctor_Copy, ValuelessByException) {
mpark::variant<int, move_thrower_t> v(42);
EXPECT_THROW(v = move_thrower_t{}, MoveConstruction);
EXPECT_TRUE(v.valueless_by_exception());
mpark::variant<int, move_thrower_t> w(v);
EXPECT_TRUE(w.valueless_by_exception());
}
#endif

View File

@ -1,22 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <string>
#include <gtest/gtest.h>
TEST(Ctor_Default, Variant) {
mpark::variant<int, std::string> v;
EXPECT_EQ(0, mpark::get<0>(v));
/* constexpr */ {
constexpr mpark::variant<int> cv{};
static_assert(0 == mpark::get<0>(cv), "");
}
}

View File

@ -1,52 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <string>
#include <gtest/gtest.h>
TEST(Ctor_Fwd, Direct) {
mpark::variant<int, std::string> v(42);
EXPECT_EQ(42, mpark::get<int>(v));
/* constexpr */ {
constexpr mpark::variant<int, const char *> cv(42);
static_assert(42 == mpark::get<int>(cv), "");
}
}
TEST(Ctor_Fwd, DirectConversion) {
mpark::variant<int, std::string> v("42");
EXPECT_EQ("42", mpark::get<std::string>(v));
/* constexpr */ {
constexpr mpark::variant<int, const char *> cv(1.1);
static_assert(1 == mpark::get<int>(cv), "");
}
}
TEST(Ctor_Fwd, CopyInitialization) {
mpark::variant<int, std::string> v = 42;
EXPECT_EQ(42, mpark::get<int>(v));
/* constexpr */ {
constexpr mpark::variant<int, const char *> cv = 42;
static_assert(42 == mpark::get<int>(cv), "");
}
}
TEST(Ctor_Fwd, CopyInitializationConversion) {
mpark::variant<int, std::string> v = "42";
EXPECT_EQ("42", mpark::get<std::string>(v));
/* constexpr */ {
constexpr mpark::variant<int, const char *> cv = 1.1;
static_assert(1 == mpark::get<int>(cv), "");
}
}

View File

@ -1,78 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <string>
#include <gtest/gtest.h>
TEST(Ctor_InPlace, IndexDirect) {
mpark::variant<int, std::string> v(mpark::in_place_index_t<0>{}, 42);
EXPECT_EQ(42, mpark::get<0>(v));
/* constexpr */ {
constexpr mpark::variant<int, const char *> cv(mpark::in_place_index_t<0>{},
42);
static_assert(42 == mpark::get<0>(cv), "");
}
}
TEST(Ctor_InPlace, IndexDirectDuplicate) {
mpark::variant<int, int> v(mpark::in_place_index_t<0>{}, 42);
EXPECT_EQ(42, mpark::get<0>(v));
/* constexpr */ {
constexpr mpark::variant<int, int> cv(mpark::in_place_index_t<0>{}, 42);
static_assert(42 == mpark::get<0>(cv), "");
}
}
TEST(Ctor_InPlace, IndexConversion) {
mpark::variant<int, std::string> v(mpark::in_place_index_t<1>{}, "42");
EXPECT_EQ("42", mpark::get<1>(v));
/* constexpr */ {
constexpr mpark::variant<int, const char *> cv(mpark::in_place_index_t<0>{},
1.1);
static_assert(1 == mpark::get<0>(cv), "");
}
}
TEST(Ctor_InPlace, IndexInitializerList) {
mpark::variant<int, std::string> v(mpark::in_place_index_t<1>{}, {'4', '2'});
EXPECT_EQ("42", mpark::get<1>(v));
}
TEST(Ctor_InPlace, TypeDirect) {
mpark::variant<int, std::string> v(mpark::in_place_type_t<std::string>{},
"42");
EXPECT_EQ("42", mpark::get<std::string>(v));
/* constexpr */ {
constexpr mpark::variant<int, const char *> cv(
mpark::in_place_type_t<int>{}, 42);
static_assert(42 == mpark::get<int>(cv), "");
}
}
TEST(Ctor_InPlace, TypeConversion) {
mpark::variant<int, std::string> v(mpark::in_place_type_t<int>{}, 42.5);
EXPECT_EQ(42, mpark::get<int>(v));
/* constexpr */ {
constexpr mpark::variant<int, const char *> cv(
mpark::in_place_type_t<int>{}, 42.5);
static_assert(42 == mpark::get<int>(cv), "");
}
}
TEST(Ctor_InPlace, TypeInitializerList) {
mpark::variant<int, std::string> v(mpark::in_place_type_t<std::string>{},
{'4', '2'});
EXPECT_EQ("42", mpark::get<std::string>(v));
}

View File

@ -1,44 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <string>
#include <gtest/gtest.h>
#include "util.hpp"
namespace lib = mpark::lib;
TEST(Ctor_Move, Value) {
// `v`
mpark::variant<int, std::string> v("hello");
EXPECT_EQ("hello", mpark::get<std::string>(v));
// `w`
mpark::variant<int, std::string> w(lib::move(v));
EXPECT_EQ("hello", mpark::get<std::string>(w));
/* constexpr */ {
// `cv`
constexpr mpark::variant<int, const char *> cv(42);
static_assert(42 == mpark::get<int>(cv), "");
// `cw`
constexpr mpark::variant<int, const char *> cw(lib::move(cv));
static_assert(42 == mpark::get<int>(cw), "");
}
}
#ifdef MPARK_EXCEPTIONS
TEST(Ctor_Move, ValuelessByException) {
mpark::variant<int, move_thrower_t> v(42);
EXPECT_THROW(v = move_thrower_t{}, MoveConstruction);
EXPECT_TRUE(v.valueless_by_exception());
mpark::variant<int, move_thrower_t> w(lib::move(v));
EXPECT_TRUE(w.valueless_by_exception());
}
#endif

View File

@ -1,26 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <gtest/gtest.h>
struct Obj {
Obj(bool &dtor_called) : dtor_called_(dtor_called) {}
~Obj() { dtor_called_ = true; }
bool &dtor_called_;
}; // Obj
TEST(Dtor, Value) {
bool dtor_called = false;
// Construct/Destruct `Obj`.
{
mpark::variant<Obj> v(mpark::in_place_type_t<Obj>{}, dtor_called);
}
// Check that the destructor was called.
EXPECT_TRUE(dtor_called);
}

View File

@ -1,141 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <gtest/gtest.h>
#include "util.hpp"
namespace lib = mpark::lib;
TEST(Get, HoldsAlternative) {
mpark::variant<int, std::string> v(42);
EXPECT_TRUE(mpark::holds_alternative<0>(v));
EXPECT_FALSE(mpark::holds_alternative<1>(v));
EXPECT_TRUE(mpark::holds_alternative<int>(v));
EXPECT_FALSE(mpark::holds_alternative<std::string>(v));
/* constexpr */ {
constexpr mpark::variant<int, const char *> cv(42);
static_assert(mpark::holds_alternative<0>(cv), "");
static_assert(!mpark::holds_alternative<1>(cv), "");
static_assert(mpark::holds_alternative<int>(cv), "");
static_assert(!mpark::holds_alternative<const char *>(cv), "");
}
}
TEST(Get, MutVarMutType) {
mpark::variant<int> v(42);
EXPECT_EQ(42, mpark::get<int>(v));
// Check qualifier.
EXPECT_EQ(LRef, get_qual(mpark::get<int>(v)));
EXPECT_EQ(RRef, get_qual(mpark::get<int>(lib::move(v))));
}
TEST(Get, MutVarConstType) {
mpark::variant<const int> v(42);
EXPECT_EQ(42, mpark::get<const int>(v));
// Check qualifier.
EXPECT_EQ(ConstLRef, get_qual(mpark::get<const int>(v)));
EXPECT_EQ(ConstRRef, get_qual(mpark::get<const int>(lib::move(v))));
}
TEST(Get, ConstVarMutType) {
const mpark::variant<int> v(42);
EXPECT_EQ(42, mpark::get<int>(v));
// Check qualifier.
EXPECT_EQ(ConstLRef, get_qual(mpark::get<int>(v)));
EXPECT_EQ(ConstRRef, get_qual(mpark::get<int>(lib::move(v))));
/* constexpr */ {
constexpr mpark::variant<int> cv(42);
static_assert(42 == mpark::get<int>(cv), "");
// Check qualifier.
static_assert(ConstLRef == get_qual(mpark::get<int>(cv)), "");
static_assert(ConstRRef == get_qual(mpark::get<int>(lib::move(cv))), "");
}
}
TEST(Get, ConstVarConstType) {
const mpark::variant<const int> v(42);
EXPECT_EQ(42, mpark::get<const int>(v));
// Check qualifier.
EXPECT_EQ(ConstLRef, get_qual(mpark::get<const int>(v)));
EXPECT_EQ(ConstRRef, get_qual(mpark::get<const int>(lib::move(v))));
/* constexpr */ {
constexpr mpark::variant<const int> cv(42);
static_assert(42 == mpark::get<const int>(cv), "");
// Check qualifier.
static_assert(ConstLRef == get_qual(mpark::get<const int>(cv)), "");
static_assert(ConstRRef == get_qual(mpark::get<const int>(lib::move(cv))),
"");
}
}
#ifdef MPARK_EXCEPTIONS
TEST(Get, ValuelessByException) {
mpark::variant<int, move_thrower_t> v(42);
EXPECT_THROW(v = move_thrower_t{}, MoveConstruction);
EXPECT_TRUE(v.valueless_by_exception());
EXPECT_THROW(mpark::get<int>(v), mpark::bad_variant_access);
EXPECT_THROW(mpark::get<move_thrower_t>(v), mpark::bad_variant_access);
}
#endif
TEST(GetIf, MutVarMutType) {
mpark::variant<int> v(42);
EXPECT_EQ(42, *mpark::get_if<int>(&v));
// Check qualifier.
EXPECT_EQ(Ptr, get_qual(mpark::get_if<int>(&v)));
}
TEST(GetIf, MutVarConstType) {
mpark::variant<const int> v(42);
EXPECT_EQ(42, *mpark::get_if<const int>(&v));
// Check qualifier.
EXPECT_EQ(ConstPtr, get_qual(mpark::get_if<const int>(&v)));
}
TEST(GetIf, ConstVarMutType) {
const mpark::variant<int> v(42);
EXPECT_EQ(42, *mpark::get_if<int>(&v));
// Check qualifier.
EXPECT_EQ(ConstPtr, get_qual(mpark::get_if<int>(&v)));
/* constexpr */ {
static constexpr mpark::variant<int> cv(42);
static_assert(42 == *mpark::get_if<int>(&cv), "");
// Check qualifier.
static_assert(ConstPtr == get_qual(mpark::get_if<int>(&cv)), "");
}
}
TEST(GetIf, ConstVarConstType) {
const mpark::variant<const int> v(42);
EXPECT_EQ(42, *mpark::get_if<const int>(&v));
// Check qualifier.
EXPECT_EQ(ConstPtr, get_qual(mpark::get_if<const int>(&v)));
/* constexpr */ {
static constexpr mpark::variant<const int> cv(42);
static_assert(42 == *mpark::get_if<const int>(&cv), "");
// Check qualifier.
static_assert(ConstPtr == get_qual(mpark::get_if<const int>(&cv)), "");
}
}
#ifdef MPARK_EXCEPTONS
TEST(GetIf, ValuelessByException) {
mpark::variant<int, move_thrower_t> v(42);
EXPECT_THROW(v = move_thrower_t{}, MoveConstruction);
EXPECT_TRUE(v.valueless_by_exception());
EXPECT_EQ(nullptr, mpark::get_if<int>(&v));
EXPECT_EQ(nullptr, mpark::get_if<move_thrower_t>(&v));
}
#endif

View File

@ -1,31 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <string>
#include <gtest/gtest.h>
TEST(Hash, Monostate) {
mpark::variant<int, mpark::monostate, std::string> v(mpark::monostate{});
// Construct hash function objects.
std::hash<mpark::monostate> monostate_hash;
std::hash<mpark::variant<int, mpark::monostate, std::string>> variant_hash;
// Check the hash.
EXPECT_NE(monostate_hash(mpark::monostate{}), variant_hash(v));
}
TEST(Hash, String) {
mpark::variant<int, std::string> v("hello");
EXPECT_EQ("hello", mpark::get<std::string>(v));
// Construct hash function objects.
std::hash<std::string> string_hash;
std::hash<mpark::variant<int, std::string>> variant_hash;
// Check the hash.
EXPECT_NE(string_hash("hello"), variant_hash(v));
}

View File

@ -1,66 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <iostream>
#include <string>
#include <gtest/gtest.h>
TEST(Variant, Intro) {
// direct initialization.
mpark::variant<int, std::string> v("hello world!");
// direct access via reference.
EXPECT_EQ("hello world!", mpark::get<std::string>(v));
// bad access.
#ifdef MPARK_EXCEPTIONS
EXPECT_THROW(mpark::get<int>(v), mpark::bad_variant_access);
#endif
// copy construction.
mpark::variant<int, std::string> w(v);
// direct access via pointer.
EXPECT_FALSE(mpark::get_if<int>(&w));
EXPECT_TRUE(mpark::get_if<std::string>(&w));
// diff-type assignment.
v = 42;
struct unary {
int operator()(int) const noexcept { return 0; }
int operator()(const std::string &) const noexcept { return 1; }
}; // unary
// single visitation.
EXPECT_EQ(0, mpark::visit(unary{}, v));
// same-type assignment.
w = "hello";
EXPECT_NE(v, w);
// make `w` equal to `v`.
w = 42;
EXPECT_EQ(v, w);
struct binary {
int operator()(int, int) const noexcept { return 0; }
int operator()(int, const std::string &) const noexcept { return 1; }
int operator()(const std::string &, int) const noexcept { return 2; }
int operator()(const std::string &, const std::string &) const noexcept {
return 3;
}
}; // binary
// binary visitation.
EXPECT_EQ(0, mpark::visit(binary{}, v, w));
}

View File

@ -1,34 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <map>
#include <memory>
#include <vector>
#include <gtest/gtest.h>
#ifdef MPARK_INCOMPLETE_TYPE_TRAITS
// https://github.com/mpark/variant/issues/34
TEST(Issue, 34) {
struct S {
S(const S &) = default;
S(S &&) = default;
S &operator=(const S &) = default;
S &operator=(S &&) = default;
mpark::variant<std::map<std::string, S>> value;
};
}
#endif
// https://github.com/mpark/variant/pull/57
TEST(Issue, 57) {
std::vector<mpark::variant<int, std::unique_ptr<int>>> vec;
vec.emplace_back(0);
}

View File

@ -1,49 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include <gtest/gtest.h>
struct JsonIsh {
JsonIsh(bool b) : data(b) {}
JsonIsh(int i) : data(i) {}
JsonIsh(std::string s) : data(std::move(s)) {}
JsonIsh(std::vector<JsonIsh> v) : data(std::move(v)) {}
mpark::variant<bool, int, std::string, std::vector<JsonIsh>> data;
};
TEST(Variant, Bool) {
JsonIsh json_ish = true;
EXPECT_TRUE(mpark::get<bool>(json_ish.data));
json_ish = false;
EXPECT_FALSE(mpark::get<bool>(json_ish.data));
}
TEST(Variant, Int) {
JsonIsh json_ish = 42;
EXPECT_EQ(42, mpark::get<int>(json_ish.data));
}
TEST(Variant, String) {
JsonIsh json_ish = std::string("hello");
EXPECT_EQ("hello", mpark::get<std::string>(json_ish.data));
}
TEST(Variant, Array) {
JsonIsh json_ish = std::vector<JsonIsh>{true, 42, std::string("world")};
const auto &array = mpark::get<std::vector<JsonIsh>>(json_ish.data);
EXPECT_TRUE(mpark::get<bool>(array[0].data));
EXPECT_EQ(42, mpark::get<int>(array[1].data));
EXPECT_EQ("world", mpark::get<std::string>(array[2].data));
}

View File

@ -1,30 +0,0 @@
# MPark.Variant
#
# Copyright Michael Park, 2015-2017
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#!/usr/bin/env bash
set -e
trap "cd ${MPARK_VARIANT_LIBCXX_SOURCE_DIR} && git checkout ." EXIT
cat <<EOF > ${MPARK_VARIANT_LIBCXX_SOURCE_DIR}/include/variant
#define mpark std
#define MPARK_IN_PLACE_HPP
$(cat ${MPARK_VARIANT_SOURCE_DIR}/include/mpark/variant.hpp)
#undef MPARK_IN_PLACE_HPP
#undef mpark
EOF
${MPARK_VARIANT_LIT} \
-v \
--param color_diagnostics \
--param cxx_under_test="${MPARK_VARIANT_CXX_COMPILER}" \
--param compile_flags=-I${MPARK_VARIANT_SOURCE_DIR}/include/mpark \
--param libcxx_site_config=${MPARK_VARIANT_LIBCXX_SITE_CONFIG} \
--param std=c++17 \
--param use_clang_verify=false \
${MPARK_VARIANT_LIBCXX_SOURCE_DIR}/test/std/utilities/variant \

View File

@ -1,60 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <string>
#include <gtest/gtest.h>
TEST(Assign_Emplace, IndexDirect) {
mpark::variant<int, std::string> v;
v.emplace<1>("42");
EXPECT_EQ("42", mpark::get<1>(v));
}
TEST(Assign_Emplace, IndexDirectDuplicate) {
mpark::variant<int, int> v;
v.emplace<1>(42);
EXPECT_EQ(42, mpark::get<1>(v));
}
TEST(Assign_Emplace, IndexConversion) {
mpark::variant<int, std::string> v;
v.emplace<1>("42");
EXPECT_EQ("42", mpark::get<1>(v));
}
TEST(Assign_Emplace, IndexConversionDuplicate) {
mpark::variant<int, int> v;
v.emplace<1>(1.1);
EXPECT_EQ(1, mpark::get<1>(v));
}
TEST(Assign_Emplace, IndexInitializerList) {
mpark::variant<int, std::string> v;
v.emplace<1>({'4', '2'});
EXPECT_EQ("42", mpark::get<1>(v));
}
TEST(Assign_Emplace, TypeDirect) {
mpark::variant<int, std::string> v;
v.emplace<std::string>("42");
EXPECT_EQ("42", mpark::get<std::string>(v));
}
TEST(Assign_Emplace, TypeConversion) {
mpark::variant<int, std::string> v;
v.emplace<int>(1.1);
EXPECT_EQ(1, mpark::get<int>(v));
}
TEST(Assign_Emplace, TypeInitializerList) {
mpark::variant<int, std::string> v;
v.emplace<std::string>({'4', '2'});
EXPECT_EQ("42", mpark::get<std::string>(v));
}

View File

@ -1,201 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <string>
#include <gtest/gtest.h>
#include <mpark/config.hpp>
#include "util.hpp"
TEST(Rel, SameTypeSameValue) {
mpark::variant<int, std::string> v(0), w(0);
// `v` op `w`
EXPECT_TRUE(v == w);
EXPECT_FALSE(v != w);
EXPECT_FALSE(v < w);
EXPECT_FALSE(v > w);
EXPECT_TRUE(v <= w);
EXPECT_TRUE(v >= w);
// `w` op `v`
EXPECT_TRUE(w == v);
EXPECT_FALSE(w != v);
EXPECT_FALSE(w < v);
EXPECT_FALSE(w > v);
EXPECT_TRUE(w <= v);
EXPECT_TRUE(w >= v);
#ifdef MPARK_CPP11_CONSTEXPR
/* constexpr */ {
constexpr mpark::variant<int, const char *> cv(0), cw(0);
// `cv` op `cw`
static_assert(cv == cw, "");
static_assert(!(cv != cw), "");
static_assert(!(cv < cw), "");
static_assert(!(cv > cw), "");
static_assert(cv <= cw, "");
static_assert(cv >= cw, "");
// `cw` op `cv`
static_assert(cw == cv, "");
static_assert(!(cw != cv), "");
static_assert(!(cw < cv), "");
static_assert(!(cw > cv), "");
static_assert(cw <= cv, "");
static_assert(cw >= cv, "");
}
#endif
}
TEST(Rel, SameTypeDiffValue) {
mpark::variant<int, std::string> v(0), w(1);
// `v` op `w`
EXPECT_FALSE(v == w);
EXPECT_TRUE(v != w);
EXPECT_TRUE(v < w);
EXPECT_FALSE(v > w);
EXPECT_TRUE(v <= w);
EXPECT_FALSE(v >= w);
// `w` op `v`
EXPECT_FALSE(w == v);
EXPECT_TRUE(w != v);
EXPECT_FALSE(w < v);
EXPECT_TRUE(w > v);
EXPECT_FALSE(w <= v);
EXPECT_TRUE(w >= v);
#ifdef MPARK_CPP11_CONSTEXPR
/* constexpr */ {
constexpr mpark::variant<int, const char *> cv(0), cw(1);
// `cv` op `cw`
static_assert(!(cv == cw), "");
static_assert(cv != cw, "");
static_assert(cv < cw, "");
static_assert(!(cv > cw), "");
static_assert(cv <= cw, "");
static_assert(!(cv >= cw), "");
// `cw` op `cv`
static_assert(!(cw == cv), "");
static_assert(cw != cv, "");
static_assert(!(cw < cv), "");
static_assert(cw > cv, "");
static_assert(!(cw <= cv), "");
static_assert(cw >= cv, "");
}
#endif
}
TEST(Rel, DiffTypeSameValue) {
mpark::variant<int, unsigned int> v(0), w(0u);
// `v` op `w`
EXPECT_FALSE(v == w);
EXPECT_TRUE(v != w);
EXPECT_TRUE(v < w);
EXPECT_FALSE(v > w);
EXPECT_TRUE(v <= w);
EXPECT_FALSE(v >= w);
// `w` op `v`
EXPECT_FALSE(w == v);
EXPECT_TRUE(w != v);
EXPECT_FALSE(w < v);
EXPECT_TRUE(w > v);
EXPECT_FALSE(w <= v);
EXPECT_TRUE(w >= v);
#ifdef MPARK_CPP11_CONSTEXPR
/* constexpr */ {
constexpr mpark::variant<int, unsigned int> cv(0), cw(0u);
// `cv` op `cw`
static_assert(!(cv == cw), "");
static_assert(cv != cw, "");
static_assert(cv < cw, "");
static_assert(!(cv > cw), "");
static_assert(cv <= cw, "");
static_assert(!(cv >= cw), "");
// `cw` op `cv`
static_assert(!(cw == cv), "");
static_assert(cw != cv, "");
static_assert(!(cw < cv), "");
static_assert(cw > cv, "");
static_assert(!(cw <= cv), "");
static_assert(cw >= cv, "");
}
#endif
}
TEST(Rel, DiffTypeDiffValue) {
mpark::variant<int, unsigned int> v(0), w(1u);
// `v` op `w`
EXPECT_FALSE(v == w);
EXPECT_TRUE(v != w);
EXPECT_TRUE(v < w);
EXPECT_FALSE(v > w);
EXPECT_TRUE(v <= w);
EXPECT_FALSE(v >= w);
// `w` op `v`
EXPECT_FALSE(w == v);
EXPECT_TRUE(w != v);
EXPECT_FALSE(w < v);
EXPECT_TRUE(w > v);
EXPECT_FALSE(w <= v);
EXPECT_TRUE(w >= v);
#ifdef MPARK_CPP11_CONSTEXPR
/* constexpr */ {
constexpr mpark::variant<int, unsigned int> cv(0), cw(1u);
// `cv` op `cw`
static_assert(!(cv == cw), "");
static_assert(cv != cw, "");
static_assert(cv < cw, "");
static_assert(!(cv > cw), "");
static_assert(cv <= cw, "");
static_assert(!(cv >= cw), "");
// `cw` op `cv`
static_assert(!(cw == cv), "");
static_assert(cw != cv, "");
static_assert(!(cw < cv), "");
static_assert(cw > cv, "");
static_assert(!(cw <= cv), "");
static_assert(cw >= cv, "");
}
#endif
}
#ifdef MPARK_EXCEPTIONS
TEST(Rel, OneValuelessByException) {
// `v` normal, `w` corrupted.
mpark::variant<int, move_thrower_t> v(42), w(42);
EXPECT_THROW(w = move_thrower_t{}, MoveConstruction);
EXPECT_FALSE(v.valueless_by_exception());
EXPECT_TRUE(w.valueless_by_exception());
// `v` op `w`
EXPECT_FALSE(v == w);
EXPECT_TRUE(v != w);
EXPECT_FALSE(v < w);
EXPECT_TRUE(v > w);
EXPECT_FALSE(v <= w);
EXPECT_TRUE(v >= w);
}
TEST(Rel, BothValuelessByException) {
// `v`, `w` both corrupted.
mpark::variant<int, move_thrower_t> v(42);
EXPECT_THROW(v = move_thrower_t{}, MoveConstruction);
mpark::variant<int, move_thrower_t> w(v);
EXPECT_TRUE(v.valueless_by_exception());
EXPECT_TRUE(w.valueless_by_exception());
// `v` op `w`
EXPECT_TRUE(v == w);
EXPECT_FALSE(v != w);
EXPECT_FALSE(v < w);
EXPECT_FALSE(v > w);
EXPECT_TRUE(v <= w);
EXPECT_TRUE(v >= w);
}
#endif

View File

@ -1,174 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <string>
#include <gtest/gtest.h>
#include "util.hpp"
TEST(Swap, Same) {
mpark::variant<int, std::string> v("hello");
mpark::variant<int, std::string> w("world");
// Check `v`.
EXPECT_EQ("hello", mpark::get<std::string>(v));
// Check `w`.
EXPECT_EQ("world", mpark::get<std::string>(w));
// Swap.
using std::swap;
swap(v, w);
// Check `v`.
EXPECT_EQ("world", mpark::get<std::string>(v));
// Check `w`.
EXPECT_EQ("hello", mpark::get<std::string>(w));
}
TEST(Swap, Different) {
mpark::variant<int, std::string> v(42);
mpark::variant<int, std::string> w("hello");
// Check `v`.
EXPECT_EQ(42, mpark::get<int>(v));
// Check `w`.
EXPECT_EQ("hello", mpark::get<std::string>(w));
// Swap.
using std::swap;
swap(v, w);
// Check `v`.
EXPECT_EQ("hello", mpark::get<std::string>(v));
// Check `w`.
EXPECT_EQ(42, mpark::get<int>(w));
}
#ifdef MPARK_EXCEPTIONS
TEST(Swap, OneValuelessByException) {
// `v` normal, `w` corrupted.
mpark::variant<int, move_thrower_t> v(42), w(42);
EXPECT_THROW(w = move_thrower_t{}, MoveConstruction);
EXPECT_EQ(42, mpark::get<int>(v));
EXPECT_TRUE(w.valueless_by_exception());
// Swap.
using std::swap;
swap(v, w);
// Check `v`, `w`.
EXPECT_TRUE(v.valueless_by_exception());
EXPECT_EQ(42, mpark::get<int>(w));
}
TEST(Swap, BothValuelessByException) {
// `v`, `w` both corrupted.
mpark::variant<int, move_thrower_t> v(42);
EXPECT_THROW(v = move_thrower_t{}, MoveConstruction);
mpark::variant<int, move_thrower_t> w(v);
EXPECT_TRUE(v.valueless_by_exception());
EXPECT_TRUE(w.valueless_by_exception());
// Swap.
using std::swap;
swap(v, w);
// Check `v`, `w`.
EXPECT_TRUE(v.valueless_by_exception());
EXPECT_TRUE(w.valueless_by_exception());
}
#endif
TEST(Swap, DtorsSame) {
struct Obj {
Obj(size_t *dtor_count) : dtor_count_(dtor_count) {}
Obj(const Obj &) = default;
Obj(Obj &&) = default;
~Obj() { ++(*dtor_count_); }
Obj &operator=(const Obj &) = default;
Obj &operator=(Obj &&) = default;
size_t *dtor_count_;
}; // Obj
size_t v_count = 0;
size_t w_count = 0;
{
mpark::variant<Obj> v{&v_count}, w{&w_count};
using std::swap;
swap(v, w);
// Calls `std::swap(Obj &lhs, Obj &rhs)`, with which we perform:
// ```
// {
// Obj temp(move(lhs));
// lhs = move(rhs);
// rhs = move(temp);
// } `++v_count` from `temp::~Obj()`.
// ```
EXPECT_EQ(1u, v_count);
EXPECT_EQ(0u, w_count);
}
EXPECT_EQ(2u, v_count);
EXPECT_EQ(1u, w_count);
}
namespace detail {
struct Obj {
Obj(size_t *dtor_count) : dtor_count_(dtor_count) {}
Obj(const Obj &) = default;
Obj(Obj &&) = default;
~Obj() { ++(*dtor_count_); }
Obj &operator=(const Obj &) = default;
Obj &operator=(Obj &&) = default;
size_t *dtor_count_;
}; // Obj
static void swap(Obj &lhs, Obj &rhs) noexcept {
std::swap(lhs.dtor_count_, rhs.dtor_count_);
}
} // namespace detail
TEST(Swap, DtorsSameWithSwap) {
size_t v_count = 0;
size_t w_count = 0;
{
mpark::variant<detail::Obj> v{&v_count}, w{&w_count};
using std::swap;
swap(v, w);
// Calls `detail::swap(Obj &lhs, Obj &rhs)`, with which doesn't call any destructors.
EXPECT_EQ(0u, v_count);
EXPECT_EQ(0u, w_count);
}
EXPECT_EQ(1u, v_count);
EXPECT_EQ(1u, w_count);
}
TEST(Swap, DtorsDifferent) {
struct V {
V(size_t *dtor_count) : dtor_count_(dtor_count) {}
V(const V &) = default;
V(V &&) = default;
~V() { ++(*dtor_count_); }
V &operator=(const V &) = default;
V &operator=(V &&) = default;
size_t *dtor_count_;
}; // V
struct W {
W(size_t *dtor_count) : dtor_count_(dtor_count) {}
W(const W &) = default;
W(W &&) = default;
~W() { ++(*dtor_count_); }
W &operator=(const W &) = default;
W &operator=(W &&) = default;
size_t *dtor_count_;
}; // W
size_t v_count = 0;
size_t w_count = 0;
{
mpark::variant<V, W> v{mpark::in_place_type_t<V>{}, &v_count};
mpark::variant<V, W> w{mpark::in_place_type_t<W>{}, &w_count};
using std::swap;
swap(v, w);
EXPECT_EQ(1u, v_count);
EXPECT_EQ(2u, w_count);
}
EXPECT_EQ(2u, v_count);
EXPECT_EQ(3u, w_count);
}

View File

@ -1,107 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/config.hpp>
enum Qual { Ptr, ConstPtr, LRef, ConstLRef, RRef, ConstRRef };
struct get_qual_t {
constexpr Qual operator()(int *) const { return Ptr; }
constexpr Qual operator()(const int *) const { return ConstPtr; }
constexpr Qual operator()(int &) const { return LRef; }
constexpr Qual operator()(const int &) const { return ConstLRef; }
constexpr Qual operator()(int &&) const { return RRef; }
constexpr Qual operator()(const int &&) const { return ConstRRef; }
};
constexpr get_qual_t get_qual{};
#ifdef MPARK_EXCEPTIONS
struct CopyConstruction : std::exception {};
struct CopyAssignment : std::exception {};
struct MoveConstruction : std::exception {};
struct MoveAssignment : std::exception {};
struct copy_thrower_t {
constexpr copy_thrower_t() {}
[[noreturn]] copy_thrower_t(const copy_thrower_t &) {
throw CopyConstruction{};
}
copy_thrower_t(copy_thrower_t &&) = default;
copy_thrower_t &operator=(const copy_thrower_t &) { throw CopyAssignment{}; }
copy_thrower_t &operator=(copy_thrower_t &&) = default;
};
inline bool operator<(const copy_thrower_t &,
const copy_thrower_t &) noexcept {
return false;
}
inline bool operator>(const copy_thrower_t &,
const copy_thrower_t &) noexcept {
return false;
}
inline bool operator<=(const copy_thrower_t &,
const copy_thrower_t &) noexcept {
return true;
}
inline bool operator>=(const copy_thrower_t &,
const copy_thrower_t &) noexcept {
return true;
}
inline bool operator==(const copy_thrower_t &,
const copy_thrower_t &) noexcept {
return true;
}
inline bool operator!=(const copy_thrower_t &,
const copy_thrower_t &) noexcept {
return false;
}
struct move_thrower_t {
constexpr move_thrower_t() {}
move_thrower_t(const move_thrower_t &) = default;
[[noreturn]] move_thrower_t(move_thrower_t &&) { throw MoveConstruction{}; }
move_thrower_t &operator=(const move_thrower_t &) = default;
move_thrower_t &operator=(move_thrower_t &&) { throw MoveAssignment{}; }
};
inline bool operator<(const move_thrower_t &,
const move_thrower_t &) noexcept {
return false;
}
inline bool operator>(const move_thrower_t &,
const move_thrower_t &) noexcept {
return false;
}
inline bool operator<=(const move_thrower_t &,
const move_thrower_t &) noexcept {
return true;
}
inline bool operator>=(const move_thrower_t &,
const move_thrower_t &) noexcept {
return true;
}
inline bool operator==(const move_thrower_t &,
const move_thrower_t &) noexcept {
return true;
}
inline bool operator!=(const move_thrower_t &,
const move_thrower_t &) noexcept {
return false;
}
#endif

View File

@ -1,124 +0,0 @@
// MPark.Variant
//
// Copyright Michael Park, 2015-2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <mpark/variant.hpp>
#include <string>
#include <sstream>
#include <gtest/gtest.h>
#include <mpark/config.hpp>
#include "util.hpp"
namespace lib = mpark::lib;
TEST(Visit, MutVarMutType) {
mpark::variant<int> v(42);
// Check `v`.
EXPECT_EQ(42, mpark::get<int>(v));
// Check qualifier.
EXPECT_EQ(LRef, mpark::visit(get_qual, v));
EXPECT_EQ(RRef, mpark::visit(get_qual, lib::move(v)));
}
TEST(Visit, MutVarConstType) {
mpark::variant<const int> v(42);
EXPECT_EQ(42, mpark::get<const int>(v));
// Check qualifier.
EXPECT_EQ(ConstLRef, mpark::visit(get_qual, v));
EXPECT_EQ(ConstRRef, mpark::visit(get_qual, lib::move(v)));
}
TEST(Visit, ConstVarMutType) {
const mpark::variant<int> v(42);
EXPECT_EQ(42, mpark::get<int>(v));
// Check qualifier.
EXPECT_EQ(ConstLRef, mpark::visit(get_qual, v));
EXPECT_EQ(ConstRRef, mpark::visit(get_qual, lib::move(v)));
#ifdef MPARK_CPP11_CONSTEXPR
/* constexpr */ {
constexpr mpark::variant<int> cv(42);
static_assert(42 == mpark::get<int>(cv), "");
// Check qualifier.
static_assert(ConstLRef == mpark::visit(get_qual, cv), "");
static_assert(ConstRRef == mpark::visit(get_qual, lib::move(cv)), "");
}
#endif
}
TEST(Visit, ConstVarConstType) {
const mpark::variant<const int> v(42);
EXPECT_EQ(42, mpark::get<const int>(v));
// Check qualifier.
EXPECT_EQ(ConstLRef, mpark::visit(get_qual, v));
EXPECT_EQ(ConstRRef, mpark::visit(get_qual, lib::move(v)));
#ifdef MPARK_CPP11_CONSTEXPR
/* constexpr */ {
constexpr mpark::variant<const int> cv(42);
static_assert(42 == mpark::get<const int>(cv), "");
// Check qualifier.
static_assert(ConstLRef == mpark::visit(get_qual, cv), "");
static_assert(ConstRRef == mpark::visit(get_qual, lib::move(cv)), "");
}
#endif
}
struct concat {
template <typename... Args>
std::string operator()(const Args &... args) const {
std::ostringstream strm;
std::initializer_list<int>({(strm << args, 0)...});
return lib::move(strm).str();
}
};
TEST(Visit, Zero) { EXPECT_EQ("", mpark::visit(concat{})); }
TEST(Visit_Homogeneous, Double) {
mpark::variant<int, std::string> v("hello"), w("world!");
EXPECT_EQ("helloworld!", mpark::visit(concat{}, v, w));
#ifdef MPARK_CPP11_CONSTEXPR
/* constexpr */ {
constexpr mpark::variant<int, double> cv(101), cw(202), cx(3.3);
struct add_ints {
constexpr int operator()(int lhs, int rhs) const { return lhs + rhs; }
constexpr int operator()(int lhs, double) const { return lhs; }
constexpr int operator()(double, int rhs) const { return rhs; }
constexpr int operator()(double, double) const { return 0; }
}; // add
static_assert(303 == mpark::visit(add_ints{}, cv, cw), "");
static_assert(202 == mpark::visit(add_ints{}, cw, cx), "");
static_assert(101 == mpark::visit(add_ints{}, cx, cv), "");
static_assert(0 == mpark::visit(add_ints{}, cx, cx), "");
}
#endif
}
TEST(Visit_Homogeneous, Quintuple) {
mpark::variant<int, std::string> v(101), w("+"), x(202), y("="), z(303);
EXPECT_EQ("101+202=303", mpark::visit(concat{}, v, w, x, y, z));
}
TEST(Visit_Heterogeneous, Double) {
mpark::variant<int, std::string> v("hello");
mpark::variant<double, const char *> w("world!");
EXPECT_EQ("helloworld!", mpark::visit(concat{}, v, w));
}
TEST(Visit_Heterogenous, Quintuple) {
mpark::variant<int, double> v(101);
mpark::variant<const char *> w("+");
mpark::variant<bool, std::string, int> x(202);
mpark::variant<char, std::string, const char *> y('=');
mpark::variant<long, short> z(303L);
EXPECT_EQ("101+202=303", mpark::visit(concat{}, v, w, x, y, z));
}