Compare commits

...

421 Commits

Author SHA1 Message Date
Peter Dimov e8cb128f99 Merge pull request #115 from Lastique/feature/remove_static_assert
Remove dependencies on Boost.StaticAssert
2026-04-25 20:51:34 +03:00
Andrey Semashev 5e1fe395b6 Remove dependencies on Boost.StaticAssert.
Boost.StaticAssert has been merged into Boost.Config, so remove
the dependency.
2026-01-22 22:52:11 +03:00
Antony Polukhin fdf2c0f646 Update copyright years 2026-01-04 11:27:21 +03:00
dependabot[bot] 0d822a9b73 Bump actions/checkout from 2 to 6 (#114)
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-29 12:31:14 +03:00
Antony Polukhin cf72f05cef Add dependabot 2025-12-24 20:23:02 +03:00
Antony Polukhin 9738f5733b CI fixes (#113) 2025-09-13 13:52:35 +03:00
Alexander Grund a803f3f1dd Update Link to regression test matrix in README (#112) 2025-08-26 13:00:54 +03:00
Antony Polukhin 1fd7271d2e Update copyright years 2025-01-08 19:52:10 +03:00
Antony Polukhin 36fc992f51 Do not test on MinGW 32-bit any more 2024-12-19 18:56:14 +03:00
René Ferdinand Rivera Morell 0fd179fbd8 Add support for modular build structure. (#111)
This is part of the effort to make the Boost libraries "modular" for build and consumption. See https://lists.boost.org/Archives/boost/2024/01/255704.php and https://github.com/grafikrobot/boost-b2-modular/blob/b2-modular/README.adoc for more information.

This PR depends on the following other PRs being merged to both develop and master branches of the respective repos:

- https://github.com/boostorg/boost/pull/854
2024-08-24 12:40:30 +03:00
Antony Polukhin b33ff4f811 Remove obsolete code (#109) 2024-01-08 20:13:32 +03:00
Antony Polukhin e37df948d7 Update copyright years 2024-01-07 12:56:27 +03:00
Andrey Semashev 9d1e62f33c Remove deprecated boost/swap.hpp include. (#108)
This header is deprecated and will be removed. There is
boost/core/invoke_swap.hpp as a replacement, but it isn't needed in this case.
2023-09-03 11:23:14 +03:00
Antony Polukhin 7b45064ed8 Drop C++03 support (#107)
Drop boost::move and boost::bind dependencies. Use Boost.PP in less cases
2023-08-25 16:02:34 +03:00
Antony Polukhin d48711fb84 update CI 2023-05-22 09:18:54 +03:00
Antony Polukhin a3368f0cf8 add C++03 deprecation warnings 2023-05-14 20:10:13 +03:00
Antony Polukhin e4447e892f Update copyright years 2023-01-19 10:24:10 +03:00
Antony Polukhin db54469549 Merge pull request #105 from fanquake/core_addressof
refactor: use core/addressof over utility/addressof
2023-01-17 15:29:41 +03:00
fanquake 8bad74942d refactor: use core/addressof over utility/addressof
The later is deprecated.
2022-12-07 16:23:37 +00:00
Antony Polukhin 78856c049d Remove MacOS run from CI as it almost always hits CI limits 2022-09-02 19:18:52 +03:00
Antony Polukhin 738e53c83b Update CI 2022-09-02 17:47:11 +03:00
Antony Polukhin 40621b1256 fix c++03 compilation 2022-09-02 16:24:24 +03:00
Antony Polukhin bab78044e4 add tests from #100 2022-09-01 14:20:47 +03:00
Antony Polukhin 73753b3d9e avoid recursive inclusion of multivisitors_cpp14_based.hpp
Fixes #101
2022-09-01 11:21:55 +03:00
Antony Polukhin a104ef5f8a Merge pull request #96 from fanquake/core_checked_delete
refactor: use core/checked_delete over checked_delete
2022-08-31 21:40:54 +03:00
Antony Polukhin edec2ffb3b Merge pull request #98 from ecatmur/patch-1
clang/c++23: disable converting move assignment
2022-08-31 21:38:26 +03:00
Ed Catmur 70ff3706c5 clang/c++23: disable converting move assignment
Workaround https://github.com/boostorg/variant/issues/97
2022-06-29 12:36:16 +01:00
fanquake 281c1791b1 refactor: use core/checked_delete over checked_delete
The later has been deprecated:
```cpp

// The header file at this path is deprecated;
// use boost/core/checked_delete.hpp instead.

```
2022-04-08 14:48:21 +01:00
Antony Polukhin d2fdf2384b update copyright years 2022-01-30 15:03:18 +03:00
Antony Polukhin 18853a6bfb disable fusion_interop test for compilers with no variadic templates 2021-09-20 22:08:50 +03:00
Antony Polukhin 2d490e74bf update the Readme 2021-09-20 21:44:48 +03:00
Antony Polukhin 445d790b2f add a test for trac issue 8721 2021-09-20 20:27:43 +03:00
Antony Polukhin 39d38baf29 remove outdated CI scripts 2021-09-20 20:14:39 +03:00
Antony Polukhin fce20c67fb simplify test to produce smaller binary 2021-09-20 18:03:27 +03:00
Antony Polukhin a8e42245e1 fix b2 warning 2021-09-20 18:02:42 +03:00
Antony Polukhin afe0914af5 disable test that is broken since C++20 2021-09-20 13:30:23 +03:00
Antony Polukhin 15f2eefbc4 Update ci.yml 2021-09-13 13:57:34 +03:00
Peter Dimov 4962a5307c Update CMakeLists.txt 2021-06-10 00:44:42 +03:00
Antony Polukhin d80cb48f02 fix issues found by inspect tool 2021-04-26 21:44:35 +03:00
Antony Polukhin 95ddf424e5 update CI from Boost.Conversion 2021-04-26 21:44:05 +03:00
Antony Polukhin 2969e124bc Merge pull request #91 from sdarwin/githubactions
GitHub Actions config
2021-04-18 14:10:16 +03:00
sdarwin 3a46150c0f Add GitHub Actions config [ci skip] 2021-03-04 18:23:02 +00:00
Antony Polukhin 8942489244 Merge pull request #89 from sdarwin/drone
Drone config
2021-01-27 10:30:36 +03:00
Antony Polukhin 5f90f71e1b Merge pull request #88 from eldiener/develop
[skip ci] Add "cxxstd" json field
2021-01-27 10:24:40 +03:00
sdarwin 4c9b00be1a add drone config [ci skip] 2021-01-26 15:29:55 +00:00
Edward Diener 945331a312 [skip ci] Add "cxxstd" json field. The "cxxstd" json field is being added to each Boost library's meta json information for libraries in order to specify the minumum C++ standard compilation level. The value of this field matches one of the values for 'cxxstd' in Boost.Build. The purpose of doing this is to provide information for the Boost website documentation for each library which will specify the minimum C++ standard compilation that an end-user must employ in order to use the particular library. This will aid end-users who want to know if they can successfully use a Boost library based on their C++ compiler's compilation level, without having to search the library's documentation to find this out. 2021-01-20 02:57:30 -05:00
Antony Polukhin dcaa5ba5ef Specify address model for MSVC
Relates boostorg/build#659
2021-01-04 11:06:38 +03:00
Antony Polukhin 9221b1513c update copyright years 2021-01-03 20:10:23 +03:00
Antony Polukhin 688a7db652 Merge pull request #87 from sdarwin/lcov
update lcov in .travis.yml
2021-01-03 12:49:52 +03:00
sdarwin 8da93b3259 update lcov in .travis.yml 2020-12-31 00:29:18 +00:00
Antony Polukhin 5e989572ae Merge pull request #83 from camolezi/camolezi-missing-include
Added missing <tuple> include
2020-07-29 19:17:54 +03:00
Lucas Camolezi b948c1a486 Added missing <tuple> include
This makes the header able to be built standalone, making possible C++ clang modules builds.
2020-07-24 11:03:10 -03:00
Antony Polukhin 03035b2f6b Fix wrong usage of boost::move (fixes #53, #82) 2020-07-23 15:28:07 +03:00
Antony Polukhin 5bd7870560 Merge pull request #81 from vgvassilev/patch-1
Add missing include
2020-07-19 10:43:24 +03:00
Vassil Vassilev 9bd4ae5684 Add missing include
Allow header file to be built standalone, in a clang C++ modules context.
2020-07-19 02:45:36 +03:00
Antony Polukhin 619d3dcc0f Merge pull request #80 from Lastique/fix_deprecated_headers
Update header locations to avoid warnings about using deprecated headers
2020-05-13 12:55:30 +03:00
Andrey Semashev 351b812267 Updated header locations to avoid warnings about using deprecated headers.
The warnings are generated by no_exceptions_support.hpp. While at it, this
commit also updates locations of several other headers that were moved and
don't generate warnings (yet).

Deprecated headers will be removed in a future release.
2020-05-11 17:28:26 +03:00
Antony Polukhin 2605aa4bff Apply BOOST_OVERRIDE to boost::bad_get::what() and boost::bad_visit::what() (fixes #78) 2020-05-05 20:22:58 +03:00
Antony Polukhin 167b5ff373 Merge pull request #79 from eldiener/develop
Changes for Embarcadero C++ clang-based compilers, targeting Boost 1.74
2020-05-02 07:54:57 +03:00
Edward Diener 1fa5aa0e0a Merge branch 'develop' of https://github.com/eldiener/variant into cppbuilder 2020-04-08 20:45:11 -04:00
Antony Polukhin 5cbe9b7e19 CI fixes 2020-04-06 11:45:47 +03:00
Antony Polukhin 38bc003df0 Update .travis.yml 2020-04-06 01:41:02 +03:00
Antony Polukhin a816eb6202 Diagnose CI issue 2020-04-05 16:12:51 +03:00
Antony Polukhin 1ba33a580e Merge pull request #77 from BartSiwek/fix_zero_as_null_pointer_constant
Fix GCC zero-as-null-pointer-constat warnings
2020-04-03 13:35:51 +03:00
Edward Diener a3f266706b Change __BORLANDC__ to BOOST_BORLANDC, which is defined in Boost config for the Embarcadero non-clang-based compilers. 2020-03-31 22:52:39 -04:00
Bart Siwek 74a9d7691c Fix GCC zero-as-null-pointer-constat warnings 2020-03-28 11:42:56 +01:00
Antony Polukhin bee77d42a8 update copyright year 2020-01-11 19:35:53 +03:00
Antony Polukhin 206d1d2bb2 Merge pull request #74 from Kojoley/remove-unused-includes
Remove unused includes
2019-12-02 07:21:33 +03:00
Nikita Kniazev 93c21189e6 Remove unused includes 2019-12-01 19:06:41 +03:00
Antony Polukhin c401edba70 fix typos 2019-06-28 22:44:06 +03:00
Antony Polukhin f34376e115 Merge pull request #66 from Kojoley/partly-mitigate-bad-clang-inlining-decision
Partly mitigate bad Clang inlining decision
2019-05-09 10:01:59 +03:00
Antony Polukhin 15a846fba0 CI fixes 2019-05-02 10:45:09 +03:00
Antony Polukhin 8f52f879b5 CI scripts update to deal with container changes 2019-05-02 10:44:06 +03:00
Antony Polukhin 3ed28d2cc5 Merge pull request #71 from boostorg/antoshkka/revert-recursive-move
Revert "Merge pull request #59 from Kojoley/recursive_wrapper-move-co…
2019-05-02 10:32:31 +03:00
Antony Polukhin b18c22a8ff Revert "Merge pull request #59 from Kojoley/recursive_wrapper-move-constructor-pointer-stealing"
This reverts commit dcbfeb9892, reversing
changes made to 055487c5bb.

Reverts adding a pointer stealing to the recursive_wrapper.
2019-05-01 20:57:40 +03:00
Antony Polukhin 0e122c38fe Merge pull request #67 from HDembinski/fix_warning
fix for unused argument warning
2019-04-23 08:56:28 +03:00
Antony Polukhin 31ed2a3b70 Merge pull request #68 from ecatmur/apply-visitor-copy-cv-ref
Copy variant cvref when determining result type
2019-04-23 08:55:00 +03:00
Ed Catmur 7331d648f4 Add test. 2019-04-21 00:50:00 +01:00
Ed Catmur 2e32903579 Merge remote-tracking branch 'origin/develop' into apply-visitor-copy-cv-ref 2019-04-20 22:22:12 +01:00
Antony Polukhin 5be655d46f Update appveyor.yml 2019-04-17 21:23:36 +03:00
Edward Catmur cbdb354a27 Copy variant cvref when determining result type
Ensures that we can e.g. call apply_visitor on a lvalue variant
2019-04-17 15:05:37 +01:00
Antony Polukhin b1d66215e1 Update appveyor.yml 2019-04-14 21:58:31 +03:00
Hans Dembinski 66ef97f655 fix_warning 2019-04-14 14:02:19 +02:00
Nikita Kniazev dd9b0c9b84 Partly mitigate bad Clang inlining decision
Because a visitor is wrapped several times during visitation it cases extra
temporaries usage and useless store and loads that can only be optimized if
the `visitation_impl` is inlined into the function that creates the wrapper.
Clang inliner decides not to inline functions even with small-sized switches,
resulting in a poor visitation code. Forceinline mark on those internal functions perceptibly improves the situation, though does not mitigate it
completely.

LLVM ticket https://bugs.llvm.org/show_bug.cgi?id=41491
2019-04-14 04:26:31 +03:00
Antony Polukhin 74ea828cde Merge pull request #65 from boostorg/feature/std-hash
Add std::hash specialization for variant (refs #49)
2019-04-12 10:55:46 +03:00
Antony Polukhin 7cc18f356c Merge pull request #63 from Kojoley/do-not-call-abort
Do not call abort in forced_return
2019-04-12 10:54:17 +03:00
Antony Polukhin dcbfeb9892 Merge pull request #59 from Kojoley/recursive_wrapper-move-constructor-pointer-stealing
recursive_wrapper move constructor pointer stealing
2019-04-12 10:52:35 +03:00
Antony Polukhin 055487c5bb Avoid git clone issues 2019-04-02 09:23:59 +03:00
Antony Polukhin 31dcc43faf Add std::hash specialization for variant (refs #49) 2019-04-01 23:45:21 +03:00
Antony Polukhin c80759d265 Merge pull request #64 from Kojoley/suppress-warnings-in-tests
Suppress warnings in tests
2019-03-27 10:19:55 +03:00
Nikita Kniazev e20f5eb7b8 Suppress warnings in tests 2019-03-26 17:43:32 +03:00
Nikita Kniazev 3cc73fe162 Do not call abort in forced_return
Reduces code bloating on Clang and MSVC, saves a branch on GCC.
2019-03-26 04:46:43 +03:00
Antony Polukhin 7ecf721f2b Merge pull request #62 from gjasny/static-visitor-public-dtor
static_visitor: Make destructor public
2019-03-16 17:59:28 +03:00
Antony Polukhin 90e7fbae48 Merge pull request #61 from Mike-Devel/min_cmake
[CMake] Add minimal cmake support
2019-03-09 21:57:30 +03:00
Gregor Jasny dd728220b0 static_visitor: Make destructor public
otherwise in C++ 17 mode Clang 8 will complain about the
protected destructor:

```
main.cpp:16:33: error: temporary of type 'boost::static_visitor<>' has protected destructor
    boost::apply_visitor(output{}, v);
                                ^
/usr/local/opt/boost/include/boost/variant/static_visitor.hpp:53:5: note: declared protected here
    ~static_visitor() = default;
    ^
```

See also discussion in https://reviews.llvm.org/D53860
2019-03-09 15:25:03 +01:00
Mike Dev 98e2674467 [CMake] Add minimal cmake support
- CMake file only supports add_subdirectory workflow.
- Provides target Boost::variant, but
  no installation and no unit tests
2019-03-08 16:23:41 +01:00
Nikita Kniazev 5c10399096 Added note about pointer stealing to never-empty guarantee design docs 2019-03-04 01:49:35 +03:00
Nikita Kniazev 11d03f3b51 Added macro to docs 2019-02-24 03:42:11 +03:00
Nikita Kniazev df4e29cf1e Use boost type_traits 2019-02-24 01:44:02 +03:00
Nikita Kniazev 32794c2340 More work done 2019-02-24 00:21:54 +03:00
Nikita Kniazev 754eaf824f Updated the documentation 2019-02-16 18:55:42 +03:00
Nikita Kniazev af07139502 refine precondition check to a function 2019-02-09 16:20:26 +03:00
Nikita Kniazev 3e93fd428c followup to recursive_wrapper pointer stealing
- Added macro to switch to the old behavior
  - Added valueless_recursive method
  - Removed nullptr and exchange

TODO:
  - Docs
2019-02-08 20:19:21 +03:00
Nikita Kniazev 1364d3ff5f recursive_wrapper move constructor pointer stealing
Instead of allocating a new object just steal the pointer from the other
recursive_wrapper. It is much cheaper and allows to mark the move constructor
noexcept (allows variant to move the object without backup copying it).
2019-01-31 21:15:10 +03:00
Antony Polukhin d069511e31 Update copyright 2019-01-17 13:00:51 +03:00
Antony Polukhin ba0746fc9d Temporary disable test for issue #53 2019-01-08 14:18:24 +03:00
Antony Polukhin 46d8b92f73 Increase fetch depth to avoid issues with submodules 2019-01-08 01:01:52 +03:00
Antony Polukhin b4acbdf3e8 Add test from #53 2019-01-07 23:32:07 +03:00
Antony Polukhin 3850c195d6 Merge pull request #57 from Kojoley/remove-edg-no-sfinae
Remove EDG 3.2 workaround
2019-01-07 23:03:07 +03:00
Nikita Kniazev 06b643df31 Cleanup includes 2019-01-06 22:15:45 +03:00
Nikita Kniazev 3c5a67e48f Removed EDG 3.2 workaround
EDG 3.2 is pretty old (the workaround added 16 years ago).
2019-01-06 20:31:18 +03:00
Antony Polukhin 500778bd7b Merge pull request #56 from Kojoley/remove-no-void-returns-workaround
Removed NO_VOID_RETURNS workaround
2019-01-06 09:25:26 +03:00
Nikita Kniazev c4370b2da2 Removed NO_VOID_RETURNS workaround
The workaround is obsolete, from Boost.Config it looks like it was used for
very old EDG2.4, VC6, and other compilers in VC6 emulation mode.
2019-01-06 00:42:58 +03:00
Antony Polukhin 6900641f4f Change coveralls url 2019-01-05 22:37:45 +03:00
Antony Polukhin 7c1171a8dd Run CI on primary repo, rather than on the fork 2019-01-05 22:27:01 +03:00
Antony Polukhin a0ad527fce Merge pull request #55 from Kojoley/fix-apply_visitor-decltype-result_type-deduction
Fixed visitor result type deduction at rvalue ref operators
2019-01-05 20:15:57 +03:00
Antony Polukhin 9af72f37bc Update variant_visit_test.cpp 2019-01-05 20:15:22 +03:00
Nikita Kniazev 4b37f9b804 Fixed visitor result type deduction at rvalue ref operators 2019-01-05 19:54:20 +03:00
Antony Polukhin 4addd1022a Minor changes for the build system 2018-12-23 16:34:00 +03:00
Antony Polukhin 283bff8e21 Merge branch 'develop' into ldionne-visit_deduce 2018-12-23 15:32:54 +03:00
Antony Polukhin 7d865cc369 CI fixes 2018-12-23 12:11:34 +03:00
Antony Polukhin 1725a7f2a1 build only in release mode on some platforms in CI 2018-12-23 09:43:33 +03:00
Antony Polukhin 2cd28cdd9c Replace boost/test/minimal.hpp from Boost.Test with boost/core/lightweight_test.hpp 2018-12-22 21:35:48 +03:00
Antony Polukhin 9b13f1cb11 Fix test for GCC 4.7 and 4.6 2018-12-15 17:10:47 +03:00
Antony Polukhin edfb83b342 ci update 2018-12-14 11:57:21 +03:00
Louis Dionne 1c4d882685 Rewrite the deduction of visitor return type
This avoids using boost::declval inside evaluated contexts, which is invalid
and will actually be diagnosed by compilers [1] when the type used inside
boost::declval has internal linkage (such as an anonymous namespace).

[1]: https://bugs.llvm.org/show_bug.cgi?id=35842
2018-11-15 18:55:58 -05:00
Antony Polukhin 4a448b2bf7 Fix unused parameter warnings 2018-10-09 11:50:45 +03:00
Antony Polukhin 50e7df744a Add missing BOOST_SYMBOL_VISIBLE to the bad_visit exception type 2018-09-18 22:41:48 +03:00
Antony Polukhin e5a75bb8e1 Revert "Specialize std::hash for boost::variant. Fixes #49"
This reverts commit d972192e54.
2018-08-12 20:56:40 +03:00
Antony Polukhin d972192e54 Specialize std::hash for boost::variant. Fixes #49 2018-08-12 20:36:12 +03:00
Antony Polukhin 98b5d42e6d Do substitute function arguments on compilers with variadic templates support (more fixes for the #42) 2018-02-21 23:10:25 +03:00
Antony Polukhin b8149a3a77 Tests and minor fixes for #42 2018-02-20 22:20:24 +03:00
Antony Polukhin 65477fa1ae Merge pull request #46 from Kojoley/fix-variadic-substitute
Fixed variadic substitute
2018-02-20 21:54:32 +03:00
Antony Polukhin 3f849aae1f Merge pull request #45 from Kojoley/patch-1
boost/math/common_factor_ct.hpp is deprecated
2018-02-20 21:53:24 +03:00
Nikita Kniazev b91d4aa40b Fixed variadic substitute 2018-02-17 21:42:31 +03:00
Nikita Kniazev 9dc4f7d697 boost/math/common_factor_ct.hpp is deprecated 2018-02-17 20:49:48 +03:00
Antony Polukhin c11d5a3365 Merge pull request #44 from DanielaE/fix/disambiguate-variant
disambiguate class variant.
2018-02-01 23:24:19 +03:00
Daniela Engert 8b073bc92f disambiguate class variant.
When compiled with C++17 features enabled, class variant is defined in both namespace 'std' and namespace 'boost'.

Signed-off-by: Daniela Engert <dani@ngrt.de>
2018-01-26 17:50:49 +01:00
Antony Polukhin 30f57614d3 Merge pull request #40 from paweldac/develop
Perfect forwarding for passing visitor in apply_visitor.
2018-01-23 10:39:28 +03:00
Antony Polukhin 8c043e1135 Merge pull request #41 from awulkiew/patch-2
Add missing include in apply_visitor_binary.hpp
2017-11-28 20:04:22 +03:00
Adam Wulkiewicz 6f66a90b47 Add missing include in apply_visitor_binary.hpp
For boost::is_lvalue_reference.
2017-11-20 19:50:41 +01:00
Pawel Dac 33784034b7 Perfect forwarding for passing visitor in apply_visitor.
Allows to catch Visitor&&, Visitor& and const Visitor&.

Removed apply_visitor with const Visitor& since it was catching inlined Visitors&&.
Passing const Visitor to result_wrapper resulted in compilation error when Visitor was mutable.
2017-11-07 23:44:43 +01:00
Antony Polukhin 7a756bc773 Updated apply_visitor docs 2017-11-05 16:33:30 +03:00
Antony Polukhin b0852f6e60 Fix test, add copyright and minor code style fix_ 2017-10-25 23:16:24 +03:00
Antony Polukhin 85416b5182 Test fixes 2017-10-25 10:06:37 +03:00
Antony Polukhin 2d09012977 Always include enable_if in apply_visitor_binary 2017-10-24 09:04:31 +03:00
Antony Polukhin 6caaa65563 Fixes for function ref quallifires usage 2017-10-22 22:25:54 +03:00
Antony Polukhin bdccd8d90e Merge pull request #1 from diplay/universal-reverence-visitable
Universal reference visitables
2017-10-18 09:09:57 +03:00
diplay f132ca7591 minor fix test 2017-10-17 13:11:05 +03:00
diplay be54a19e1b mixed tests 2017-10-17 13:01:36 +03:00
diplay f87445832e change typename template parameter to bool 2017-10-17 11:43:44 +03:00
diplay 28f8707515 compilation conditions for multivisitor lambda tests 2017-10-13 21:53:42 +03:00
diplay 49e4f90e74 cpp14 multivisitors tests and fix 2017-10-13 15:09:21 +03:00
diplay 1cf3d885bc binary c++14 rvalue move semantics 2017-10-13 14:33:54 +03:00
diplay 3cab439be0 unary c++14 rvalue move semantics 2017-10-13 14:22:55 +03:00
diplay ec3c0964f1 [wip] c++14 multivisitor with rvalue support 2017-10-13 12:24:30 +03:00
diplay d933b7cf01 [wip] fix multivisotors cpp11 2017-10-13 12:14:42 +03:00
diplay 61c3872905 [wip] fixed multivisitor with move semantics 2017-10-13 11:24:00 +03:00
diplay c15f85475e [wip] trying to make rvalue multivisit work 2017-10-13 01:24:53 +03:00
diplay 51f5b50dc9 [wip] binary apply visitor move semantics 2017-10-12 14:00:54 +03:00
diplay 6d0566898e [wip] fix test crashes from previous commit 2017-10-11 16:33:58 +03:00
diplay 09bbcadbc1 [wip] unary visit with rvalue references 2017-10-11 14:45:56 +03:00
diplay bb9473dfd0 remove hardcoded -std from toolset params 2017-10-10 13:16:25 +03:00
diplay d4202b8a3f more structured tests 2017-10-10 12:50:07 +03:00
diplay 18fb1d3d7f rvalue and const lvalue reference visitables for multivisitors 2017-10-10 12:37:55 +03:00
diplay ce556f3371 reduce copy-paste 2017-10-10 12:08:08 +03:00
diplay 86142eccda ticket #6971 fix 2017-10-09 17:47:27 +03:00
Antony Polukhin ea73f3fb81 Drop some of the new warning suppressions, because they are too global (and some day may hide warnings for just-added issues) 2017-09-26 21:42:01 +03:00
Antony Polukhin 18bf0a18f3 Merge remote-tracking branch 'danielae/feature/qoi-warning' into develop 2017-09-26 21:19:39 +03:00
Antony Polukhin 0fad382bb0 Merge pull request #36 from MarcelRaad/msvc_warning
Fix warning in warning suppression code
2017-07-13 21:00:50 +03:00
Marcel Raad 5e8814db76 Fix warning in warning suppression code
MSVC complained that this expression had no effect. Cast to void to
silence the warning.
2017-07-13 16:17:25 +02:00
Antony Polukhin 15689b8e4f Merge pull request #35 from very-cool-name/fix_joint_view
Fix joint view
2017-07-07 10:54:44 +03:00
Mike Maximoff a904c0ebbc make_variant_over does not revert type sequence. Added tests using variant.which(). 2017-07-06 12:38:34 +03:00
very-cool-name b2339c4c8d Merge branch 'develop' into fix_joint_view 2017-07-04 21:02:16 +03:00
Mike Maximoff 8bf53ce9dd Variadic templates make_variant_over still needs copying t work properly. Removed specialization. 2017-07-04 18:35:35 +03:00
Mike Maximoff ad50a55c65 Merge branch 'develop' into fix_joint_view
# Conflicts:
#	include/boost/variant/variant.hpp
2017-07-04 18:12:40 +03:00
Mike Maximoff 1adb0b7f3a Fix works with mpl::list instead of mpl::vector 2017-07-04 17:44:11 +03:00
Daniela Engert 6c2c2fd506 Silence msvc compiler warnings about constant conditional expressions, returning the adress of local variables, and unused formal parameters.
Signed-off-by: Daniela Engert <dani@ngrt.de>
2017-06-08 19:10:43 +02:00
Antony Polukhin d393d391b8 Uppdated the reference sections for the get* functions 2017-06-05 23:13:28 +03:00
Antony Polukhin b108cfb82a Merge pull request #33 from ASverdlov/develop
Add rvalue get<>() support + tests.
2017-05-30 23:36:55 +03:00
Albert Sverdlov 5b61db29a3 Remove unnecessary variable 2017-05-29 20:37:59 +03:00
Albert Sverdlov 33f9fd4d51 Remove # symbol 2017-05-29 18:42:56 +03:00
Albert Sverdlov f62f657d4e Fix tests; Fix copyright; Remove unnecessary mpl::not 2017-05-29 18:42:25 +03:00
Albert Sverdlov c46ede5c1a Restore empty comment line 2017-05-26 02:57:21 +03:00
Albert Sverdlov 1cc3765061 Handle get<U&>() case; Add tests 2017-05-26 02:54:28 +03:00
Albert Sverdlov 5c3bd61de8 Add rvalue get<> 2017-05-23 17:07:26 +03:00
Antony Polukhin 9851ea7e69 Fixed formatting in README 2017-05-19 21:52:04 +03:00
Antony Polukhin 575c5796b4 Merge remote-tracking branch 'adambadura/master' into develop 2017-05-19 21:51:05 +03:00
Adam Badura 76b592ae1f Solution for ticket 13037 (https://svn.boost.org/trac/boost/ticket/13037).
Missing include of <boost/type_traits/is_const.hpp> added in
<boost/variant/polymorphic_get.hpp>.
2017-05-19 08:50:09 +02:00
Antony Polukhin eebee81acf Speedup AppveyorCI builds 2017-05-18 23:23:28 +03:00
Antony Polukhin a0e8a7f831 Merge pull request #31 from boostorg/revert-30-fix_joint_view
Revert "unpack types from mpl::joint_view for make_variant_over function (tra…"
2017-04-23 09:18:15 +03:00
Antony Polukhin 872c734eea Revert "unpack types from mpl::joint_view for make_variant_over function (tra…" 2017-04-23 09:17:10 +03:00
Antony Polukhin d9626aef6f Updated AppveyorCI script 2017-04-22 20:59:12 +03:00
Antony Polukhin 5f30dc2d2e Merge pull request #30 from very-cool-name/fix_joint_view
unpack types from mpl::joint_view for make_variant_over function (tra…
2017-04-22 09:04:09 +03:00
Mike Maximoff caf6264c58 Added test of related issue with mpl::set (trac #10041) 2017-03-19 23:06:26 +03:00
Mike Maximoff f015b13890 More generic solution to support more typed of sequences and variadic template solution to speed up compilation 2017-03-19 22:40:14 +03:00
Mike Maximoff bf0ab5ff84 unpack types from mpl::joint_view for make_variant_over function (trac #8554) 2017-03-15 21:16:47 +03:00
Antony Polukhin 215704dfb3 Run MinGW tests too (thanks to Pavel Filinov for showing that appveyor ability) 2017-02-24 08:22:01 +03:00
Antony Polukhin fc7a665272 Make polymorphic_*get work as *get in undocumented border cases and fix tests (trac 11950) 2017-02-02 22:19:37 +03:00
Antony Polukhin 82f0ef1c1a Fix issue: recursive_wrapper is not nothrow move constructible 2017-01-22 12:29:58 +03:00
Antony Polukhin fd2a03827f Do not depend on std::array 2017-01-20 22:22:41 +03:00
Antony Polukhin fbad41fb90 Added test case from trac ticket 7120 2017-01-20 22:21:49 +03:00
Antony Polukhin 90464a57f2 Revert variadic templates for MSVC (it still has issues) 2017-01-19 01:26:46 +03:00
Antony Polukhin 0e489993d3 Enabling variadic templates for MSVC2015Upade1 - typo fix again (trac 12236) 2017-01-19 01:07:47 +03:00
Antony Polukhin bc01e92c25 Enabling variadic templates for MSVC2015Upade1 - typo fix (trac 12236) 2017-01-19 00:39:23 +03:00
Antony Polukhin ce1ae2d2d4 Enabling variadic templates for MSVC2015Upade1 (trac 12236) 2017-01-18 22:46:53 +03:00
Antony Polukhin 761f634e72 Merge pull request #29 from awulkiew/patch-1
Add missing space between > > in is_nothrow_move_constructible specialization.
2017-01-14 12:17:37 +04:00
Adam Wulkiewicz ef7012b359 Add missing space between > > in is_nothrow_move_constructible specialization. 2017-01-14 03:05:01 +01:00
Antony Polukhin 217ee7f9ff Merge pull request #28 from very-cool-name/fix_gcc6_crash
Fix gcc 6 fail, when it tries to determine whether recursive_wrapper …
2017-01-14 02:24:58 +04:00
Mike Maximoff effbf189b6 Used __cpp_inheriting_constructors as guard. Fixed unused variable warnings. 2017-01-13 23:46:08 +03:00
Mike Maximoff ec27e4deb7 Fix gcc 6 fail, when it tries to determine whether recursive_wrapper is_nothrow_move_constructible (trac #12680) 2017-01-12 14:18:49 +03:00
Antony Polukhin e0b65c01a8 Merge pull request #27 from very-cool-name/fix_recursive_variant_
Fixed forbidden construction of variant from recursive_variant_ (trac…
2016-12-21 23:43:30 +04:00
Mike Maximoff 65d1fb524b Tests hash_recursive_variant only on compilers with unordered_set and template aliases. Copyright and original trac issues added. 2016-12-21 14:25:02 +03:00
Mike Maximoff 3aacf56026 Fixed forbidden construction of variant from recursive_variant_ (trac #12508, #12645) 2016-12-20 13:57:08 +03:00
Antony Polukhin f739850467 Fix coverage info gathering in travisCI script for GCC-6 2016-12-04 02:23:08 +03:00
Antony Polukhin bc54fbb10e Fixing coverage collection in travis script 2016-12-03 22:18:26 +03:00
Antony Polukhin 6655e8c11f Updated CI scripts 2016-11-19 18:35:53 +03:00
Rene Rivera 34036da7dc Add, and update, documentation build targets. 2016-10-07 23:07:37 -05:00
Antony Polukhin fac387ae38 MMore fixes for noreturn 2016-09-06 08:57:43 +03:00
Antony Polukhin 9342505270 Use std::abort in forced_return() to leverage [[noreturn]] attribute, improve generated code and fix warnings 2016-09-03 11:55:03 +03:00
Antony Polukhin a6a8fc09f1 Merge pull request #25 from Kojoley/fix-noreturn-does-return-warning
Fixes `"noreturn" does return` warning in release mode. #24 follow-up
2016-09-03 12:13:38 +04:00
Nikita Kniazev d5bb909689 Fixes "noreturn" does return warning in release mode. #24 follow-up 2016-09-02 22:17:36 +03:00
Antony Polukhin ecb67c03a9 Merge pull request #23 from Kojoley/suppress-weak-vtables-warning
Suppress weak vtables warning
2016-08-31 22:56:50 +04:00
Antony Polukhin 889b4f2ab2 Merge pull request #24 from Kojoley/fix-missing-noreturn
Fixed missing noreturn
2016-08-31 22:56:16 +04:00
Nikita Kniazev 9a1499ff91 Fixed missing noreturn 2016-08-31 21:37:05 +03:00
Nikita Kniazev f46206a519 Suppress weak vtables warning 2016-08-31 19:41:58 +03:00
Antony Polukhin f43b4819b3 Merge pull request #22 from hia3/more-addressof
Use addressof in strict_get
2016-08-29 23:02:11 +04:00
sms d1213fc419 Use addressof in strict_get 2016-08-29 18:34:24 +03:00
Antony Polukhin ae466ff353 Added tests from pull request 21 2016-07-23 23:10:59 +03:00
Antony Polukhin 2c0ac80950 Merge pull request #21 from amedama41/develop
Suppress implicit instantiation of MPL end iterator
2016-07-21 23:34:16 +04:00
amedama41 14be0f4555 Suppress implicit instantiation of MPL end iterator 2016-07-20 23:22:49 +09:00
Antony Polukhin dbb832c81e Update the maintainers list 2016-07-12 21:28:40 +03:00
Antony Polukhin 0dcec63b04 Another fix for incomplete types issue. is_variant_constructible_from attempts to construct not only recursive_wrapper<incomplete_type> from incomplete type, but also all the other types of variant from incomplete type. So boost::is_constructible<some_type, incomplete_type> was being called. Issue was fixed by leaving the recursive_wrapper for the right part of the boost::is_constructible and specializing the is_constructible for all the occurances of boost::recursive_wrapper. 2016-06-10 21:00:11 +03:00
Antony Polukhin 927280570a Another attempt to workaround is_constructible<incomplete_type> behavior of clang+libc++ 2016-06-09 23:00:41 +03:00
Antony Polukhin 5dab3b7ab9 Another attempt to workaround partial classes compilation with clang+libc++ (issue preventing boost::spirit::info from compilation) 2016-06-07 22:19:37 +03:00
Antony Polukhin b84f8c2141 boost::recursive_wrapper related tests for non-complete types + include recursive_wrapper.hpp in variant.hpp to avoid breaking existing code 2016-06-04 11:01:40 +03:00
Antony Polukhin f4b7d2e50c Fixed double quotes in includes (trac 12057) 2016-06-02 22:15:33 +03:00
Antony Polukhin 397c2f14f8 Dropped BOOST_VARIANT_NO_REFERENCE_SUPPORT macro and dropped support for compilers without SFINAE (trac 12250) 2016-06-02 22:06:23 +03:00
Antony Polukhin 7259ab9b32 Make sure that overloads for variant assingnment are not abiguous when assigning structure derived from variant 2016-06-02 21:52:04 +03:00
Antony Polukhin 38ea840ae3 Merge pull request #20 from pluehne/issue-documentation-typos
Typos in Documentation
2016-06-02 22:46:16 +04:00
Patrick Lühne b5949cbd6b Fixed whitespace issues in documentation. 2016-06-01 00:27:28 +02:00
Patrick Lühne 84c74fefcf Fixed typos in documentation. 2016-06-01 00:27:14 +02:00
Antony Polukhin d23cdd3502 Fixed variant construction from classes derived from variant (trac 7120, trac 10278, trac 12155) 2016-05-30 20:11:22 +03:00
Antony Polukhin 2e9d5566b3 Fix travis builds 2016-05-30 20:09:08 +03:00
Antony Polukhin 70f9db1f35 Added missing include 2016-05-28 09:39:33 +03:00
Antony Polukhin 9f234aefa4 Fix typo 2016-05-28 01:48:47 +03:00
Antony Polukhin 85d7a5c72d Added test for issue with implicit conversion operator (trac 11602) 2016-05-28 01:46:47 +03:00
Antony Polukhin 082732aad8 Fix comparisons when variant holds non-const reference (trac 11751) 2016-05-28 01:32:29 +03:00
Antony Polukhin b3650685f9 Variant constructors and assignment operators now do not participate in overload resolutions if variant can not hold the input type (trac 5871, trac 11602) 2016-05-28 01:29:52 +03:00
Antony Polukhin 5bfb9dbed9 Fix noexcept for variant's move-assignment (trac #11696) 2016-05-17 21:38:14 +03:00
Antony Polukhin 464cca5bfa Merge pull request #19 from joto/patch-1
fix typo
2016-02-03 20:01:11 +03:00
Jochen Topf 32732fac1f fix typo 2016-02-02 09:31:44 +01:00
Antony Polukhin d2db11c5a4 Merge pull request #18 from jakobandersen/develop
Missing include in recursive_wrapper_fwd.hpp.
2015-12-30 00:20:26 +04:00
Jakob Lykke Andersen 29db6e3e21 Fix compilation error due to missing include.
Add include for mpl::true_/false_.
2015-12-25 19:05:15 +01:00
Antony Polukhin 5cfa5fcf87 Modernize .travis.yml 2015-12-18 22:10:18 +03:00
Antony Polukhin ec32d3c1c8 Fixed some warnings in test 2015-12-14 19:15:49 +03:00
Antony Polukhin 9807275140 Merge pull request #17 from jzmaddock/patch-4
Workaround for Oracle C++ compiler
2015-09-12 21:26:11 +04:00
Antony Polukhin 1da1f36c3e Merge pull request #16 from jzmaddock/type_traits_fix
Remove files which use deprecated type_traits features, and aren't in…
2015-09-12 19:17:04 +04:00
Antony Polukhin 73645c78b4 Travis fix 2015-08-22 19:45:09 +03:00
Antony Polukhin c8c769eeb8 Install valgrind in travisci runs 2015-08-22 16:24:53 +03:00
Antony Polukhin 81218d0f60 Fix travis build 2015-08-22 12:54:36 +03:00
Antony Polukhin d80f9b7f15 TravisCI now runs using valgrind 2015-08-22 12:24:37 +03:00
jzmaddock c3ee00a45e Workaround for Oracle C++ compiler 2015-08-20 13:34:11 +01:00
jzmaddock 3404daa2fa Remove files which use deprecated type_traits features, and aren't included by anything else anyway. 2015-07-25 11:58:55 +01:00
Antony Polukhin 1de9d246c0 Quckfix for C++14 tests 2015-06-26 00:53:21 +03:00
Antony Polukhin 0b9cb5792b Fixed some warnings in tests 2015-06-22 00:26:10 +03:00
Antony Polukhin aad58b5fe5 Fix issue with detection of result_type in has_result_type trait when result_type is a reference (refs track 11251,11285) 2015-06-17 21:25:11 +03:00
Antony Polukhin 34e2a9dec8 Relax compile time checks for all the 'get' functions and add more tests 2015-06-17 00:42:42 +03:00
Antony Polukhin 2b2cc6543c Fix error with missing include, that was found by Maarten de Vries 2015-05-10 21:53:27 +03:00
Antony Polukhin 3d4b1ed964 More RTTI off tests and make sure that all the tests pass with RTTI off 2015-04-25 15:06:39 +03:00
Antony Polukhin 7a0b343681 Merge pull request #12 from eldiener/develop
Removed reliance on deprecated type_traits header
2015-04-15 10:46:07 +04:00
Edward Diener a9049106d7 Removed reliance on deprecated type_traits header 2015-04-02 12:26:22 -04:00
Antony Polukhin 5c9b7b0105 Fix typo in docs 2015-03-09 14:47:10 +03:00
Antony Polukhin da6494128d Do check result type detection for delayed visitation ONLY if variadic templates are available 2015-02-11 12:05:47 +03:00
Antony Polukhin b38a79116e Merge branch 'develop' into alexhenrie-master 2015-01-31 18:03:23 +03:00
Alex Henrie 812f62ba79 Correct spelling of "suppress" and "ensure" 2015-01-30 15:25:40 -07:00
Antony Polukhin 1cec2c9e93 Disable variadic templates for MSVC-14 because of compiler implementation bugs 2015-01-27 16:11:40 +03:00
Antony Polukhin e00c75c20d Continue fixes, pointed out by Adam Wulkiewicz: removed unnecessary reference_content.hpp include, added missing static_assert.hpp include 2015-01-08 14:06:59 +03:00
Antony Polukhin adfd722858 Merge pull request #9 from awulkiew/fix/get
Your fix seems right. `resursive_wrapper_fwd.hpp` is meant to be lightweight and included everywhere.
2015-01-08 13:58:13 +03:00
Antony Polukhin 57090d9209 Fix test compilation (missing header) 2015-01-04 20:19:51 +03:00
Antony Polukhin b3aedaabc4 Merge pull request #10 from awulkiew/fix/headers
Add missing header in variant.hpp
2015-01-04 19:40:48 +03:00
Adam Wulkiewicz d05232522b Add missing header in variant.hpp
because of the recent TypeTraits dependency drop in Move.
2015-01-04 15:19:55 +01:00
Adam Wulkiewicz 428433f497 Add missing headers in get.hpp and element_index.hpp 2014-12-31 16:44:47 +01:00
Antony Polukhin da89ab5633 Add test for unambiguous call to swap (refs trac #10882) 2014-12-26 16:49:31 +03:00
Antony Polukhin 1e1a81536c Fix ambiguous cal to swap (refs trac #10882) 2014-12-26 15:12:34 +03:00
Antony Polukhin 36a45459f1 Use unified travis script 2014-12-18 22:50:38 +03:00
Antony Polukhin 7c8b70cb9d Include variant_fwd.hpp to avoid issues with undefined BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES 2014-12-17 10:43:51 +03:00
Antony Polukhin 3b84e2b981 Make the variant_nonempty_check check variant behavior on different internal policies: with/without fallback type + throw/nothrow copyable + throw/nothrow movable 2014-12-12 17:01:17 +03:00
Antony Polukhin 6db01d6494 Fixed a bug with copy constructing a backup holder; changed some tests 2014-12-12 16:05:52 +03:00
Antony Polukhin a090e75efe Throw exceptions on specified assignment numer N in variant_nonempty_check and make tests run on a multiple different Ns 2014-12-12 14:22:37 +03:00
Antony Polukhin ceb56996d6 Minor improvement to the autotest script 2014-12-11 19:40:34 +03:00
Antony Polukhin 12ab1675c7 Another attempt to improve tests coverage 2014-12-11 18:46:29 +03:00
Antony Polukhin a79b3978a5 Improve tests coverage: add tests to ensure varinat is in correct state after exception in assignment of move assignemnt functions; make sure that recursive varinats swap and assign well 2014-12-11 17:47:19 +03:00
Antony Polukhin 3e9aec5371 Avoid some non essential hard for compilers tests, improve tests coverage 2014-12-11 15:21:35 +03:00
Antony Polukhin ff52de9d5a Merge branch 'master' into develop 2014-12-10 14:46:33 +03:00
Antony Polukhin e2525d1baf Merge branch 'travisci' 2014-12-10 14:45:24 +03:00
Antony Polukhin 8c385d9874 Final update of README.md 2014-12-10 14:45:00 +03:00
Antony Polukhin 1a67de834e Updated README.md 2014-12-10 14:37:55 +03:00
Antony Polukhin 4ea8838167 Updated README.md 2014-12-10 14:33:14 +03:00
Antony Polukhin cbf4bbf1b1 Apply naming recomendations from mailing list discussion: unsafe=>relaxed, safe=>strict 2014-12-10 14:03:33 +03:00
Antony Polukhin 46250fa7d2 Make polymorphic_get U type compile time checked, add more tests and improve docs. Use strict as a default policy for polymorphic_get and get (as recomended at mailing list discussions) 2014-12-10 13:32:18 +03:00
Antony Polukhin bcf506a296 Started the work on polymorphic_get to determinate sanity/safety of getting Base type. Fixed an issue with polymorphic_get<const final>. More tests, added safe_get and unsafe_get methods. Minor update of the docs 2014-12-09 20:50:18 +03:00
Antony Polukhin 1231f51501 Initial implementation of a metaprogramming function, that is capable of detecting element index in variant::types. Some tests to make sure that no old valid code was broken 2014-12-09 17:31:41 +03:00
Antony Polukhin 5cd1e3ee85 More tests and minor fixes for variadic multi visitation 2014-12-08 14:00:42 +03:00
Antony Polukhin 0231eefd43 More docs and tests for new variadic templates related features; tune apply_visitor(visitor) to use variadic templates and be suitable for visitors with any count of input opertors 2014-12-05 18:02:46 +03:00
Antony Polukhin 2770d7569e Variadic templates based multivisitors now compile, result_type is determinated automatically if required 2014-12-05 14:51:58 +03:00
Antony Polukhin 6fff67381e Merge branch 'develop' into variadic_multivisitors 2014-12-05 12:01:38 +03:00
Antony Polukhin 6db941f3dd Added missing relational operators and their docs (refs trac #10811 and #8620) 2014-12-03 20:42:10 +03:00
Antony Polukhin ecdde80ea5 Some thoughts about multivisitors based on variadic templates 2014-12-03 19:25:47 +03:00
Antony Polukhin 940cfef1f6 Simplify Multi visitation section in Tutorial (refs trac #10653) 2014-12-02 19:52:26 +03:00
Antony Polukhin adb3d5c9bb Removed deprecated advice (refs trac #10273) 2014-12-02 19:16:19 +03:00
Antony Polukhin 20c7019799 Make sure that we do not occasionally disable variadic templates for Clang (refs trac #Clang compiler defines GNUC) 2014-12-02 19:10:18 +03:00
Antony Polukhin 6e31806038 Autodetect visitation result type for binary visitors (refs svn #10837) 2014-12-02 18:59:58 +03:00
Antony Polukhin f8a29a0d2f Autodetect visitation return type for unary visitors (refs svn #10837) 2014-12-02 17:48:57 +03:00
Antony Polukhin 81ef9229fb remove executable permission from a source file 2014-11-26 11:36:12 +03:00
Antony Polukhin 21eeb2e4d4 More Coverall fixes 2014-09-18 16:59:56 +04:00
Antony Polukhin 7fc1b93794 Final fixes 2014-09-18 16:42:30 +04:00
Antony Polukhin 4352cb4c17 Attempt to improve coverage tests 1 2014-09-18 16:24:36 +04:00
Antony Polukhin 2131e0255f Attempt to improve coverage tests 2014-09-18 16:15:25 +04:00
Antony Polukhin 9ae87bfbd0 More TravisCI fixes and README improved 2014-09-18 15:24:52 +04:00
Antony Polukhin 29e6bd2c43 More TravisCI fixes 2014-09-18 15:05:20 +04:00
Antony Polukhin 4a55d87943 Script unification and minor improvements 2014-09-18 14:52:32 +04:00
Antony Polukhin ad350dde6e Script unification 2014-09-18 14:37:56 +04:00
Antony Polukhin 302afed1ba unification of script 2014-09-18 14:17:42 +04:00
Antony Polukhin 2569ca18ce Fixes 1 2014-09-18 13:56:40 +04:00
Antony Polukhin a8b920532d Fixes 2014-09-18 13:44:47 +04:00
Antony Polukhin 384ac0dd4a Do not use nedpod archive 2014-09-18 13:37:49 +04:00
Antony Polukhin 3bb91f9a39 Add travisCI integration 2014-09-18 11:48:43 +04:00
Antony Polukhin ed614a6260 Applied patches from Boost.TypeIndex 2014-09-02 12:04:27 +04:00
Antony Polukhin 30adb7fd45 Merge pull request #8 from danieljames/metadata
Create metadata file.
2014-08-18 19:54:37 +04:00
Daniel James db42afbdfa Add metadata file. 2014-08-18 15:12:28 +01:00
Antony Polukhin 8f111d3126 Fix compilation of static visitors on GCC4.5.1 2014-08-15 11:48:26 +04:00
Antony Polukhin 7c85a3a6bb Merge pull request #6 from jzmaddock/patch-2
Update Jamfile.v2
2014-08-13 22:49:01 +04:00
jzmaddock 433d3aecab Update Jamfile.v2
There can only be one project named boost/doc and we have that already under /doc/
Rename to something unique.
2014-08-13 18:39:23 +01:00
Antony Polukhin 1b50119b21 Fix issues reported by Boost Inspection Tool 2014-08-01 14:09:36 +04:00
Antony Polukhin cf3875bc22 Merge branch 'master' into develop 2014-08-01 14:07:14 +04:00
Antony Polukhin 65dae1db5a Merge branch 'develop' 2014-06-25 20:26:25 +04:00
Antony Polukhin 4ad95f185b Minor improvements related to the forced_return() function 2014-06-23 21:04:48 +04:00
Antony Polukhin 0367512bc7 Fix for pull request #4 : make it possible to return movable-only structures; reduce resulting binary size by removing duplicate BOOST_ASSERTs 2014-06-23 20:10:10 +04:00
Antony Polukhin e1a611c000 Merge branch 'develop' 2014-05-18 11:58:19 +04:00
Antony Polukhin 134dfbf46e Do not use in hash tests. Added a few more tests for variant hashing 2014-05-07 18:49:09 +04:00
Antony Polukhin 92a530a2b9 Merge branch 'develop' 2014-05-04 14:12:28 +04:00
Antony Polukhin 9bc9c1c143 Do not use variadic templates on platforms that do not have full support of that feature 2014-04-24 11:53:00 +04:00
Antony Polukhin 5398f31ea2 Merge pull request #3 from ecatmur/make-recursive-variant-variadic
Substitute recursive variant tag within variadic templates (e.g. tuple)
2014-04-11 14:20:37 +04:00
Ed Catmur e30800b534 Substitute recursive variant tag within variadic templates (e.g. tuple)
Unspecialize variadic substitute on Arity to prevent ambiguity with boost::variant<...> partial specialization in recursive_variant.hpp; add test.

Add check for BOOST_NO_CXX11_HDR_TUPLE, in case we end up with a compiler with variadic templates but no std::tuple
2014-04-11 01:47:09 +01:00
Antony Polukhin 9b04ff9221 Merge branch 'develop' 2014-02-21 15:02:39 +04:00
Antony Polukhin 7a5b0f2538 Suppress warnings and add BOOST_SYMBOL_VISIBLE to exceptions 2014-02-11 11:05:33 +04:00
Antony Polukhin 01a9630c37 Merge branch 'develop' 2014-02-04 15:23:34 +04:00
Antony Polukhin 0396d6c73d Allow rvalue-preformance-tests compilation in C++03 mode. This may be useful to measure performance of copy constructors/operators in C++03 2014-02-03 16:52:34 +04:00
Antony Polukhin 63fb3ff427 Do not use variadic templates on MSVC2013 + add some tests to make sure that Spirit metaprogramming code works well with macro from Variant 2014-01-22 11:52:03 +04:00
Antony Polukhin 0d226eb597 Create first merge point for Git 2013-12-30 18:24:43 +04:00
Antony Polukhin 464799f446 Refs #9479 (polymorphic_get for Boost.Variant) 2013-12-10 16:13:49 +04:00
Antony Polukhin f59cdef172 Fix preprocessor code that detects variadic templates usabilty 2013-12-09 12:39:10 +04:00
Antony Polukhin e20324e2c4 Updated docs and variadic templates support 2013-12-09 11:50:15 +04:00
Antony Polukhin 592e1b5339 Merge some more changes to variant that accidentaly were not merged in r86650
[SVN r86676]
2013-11-13 12:24:00 +00:00
Antony Polukhin a2523c620d Merge some changes to variant that accidentaly were not merged in r86650
[SVN r86674]
2013-11-13 12:20:05 +00:00
Antony Polukhin e70b03583f Merge from trunk:
* dropped support of antique compilers
* fixed issue with ambiguity in swap (fixes #2839)
* added conditional noexcepts to move assignments, default and move constructors (fixes #7911)
* experimental variadic templates support (refs #9163)
* bunch of size optimizations for assignments and move assignments (refs #7960)
* minor changes and size optimizations

[SVN r86650]
2013-11-12 10:16:15 +00:00
Stephen Kelly 724f7fdebc Simplify multi-component ifdefs containing BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
[SVN r86248]
2013-10-11 23:20:59 +00:00
Stephen Kelly 037af28f3d Remove BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Process #ifndef...#else...#endif blocks.

[SVN r86245]
2013-10-11 23:17:48 +00:00
Stephen Kelly ee19ae6fb5 Remove BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Process #ifdef...#endif blocks.

[SVN r86243]
2013-10-11 23:13:10 +00:00
Antony Polukhin 2cbea14c39 More noexcept modifiers, especially for some of boost::get(T*) and assign/move_assign helpers (refs #7960)
[SVN r86158]
2013-10-04 06:48:59 +00:00
Antony Polukhin 3ed1af5e79 Detect noexcept specification for default constructor of variant (refs #7911)
[SVN r86135]
2013-10-02 13:13:17 +00:00
Antony Polukhin ac98e0ce4e Removed duplicate code in assign<->move_assign, added const modifiers (refs #7960)
[SVN r86134]
2013-10-02 12:41:09 +00:00
Antony Polukhin 57f1c98b29 Mark move assignment with noexcept if possible (refs #7911)
[SVN r86054]
2013-09-30 14:55:28 +00:00
Antony Polukhin 0d43b3ec34 Commit missing test file for Boost.Variant and uncomment line in Jamfile (refs #2839)
[SVN r86049]
2013-09-30 07:39:25 +00:00
Rene Rivera b0ec38cbc4 Fix overall Boost testing because of missing file.
[SVN r85991]
2013-09-28 20:02:17 +00:00
Stephen Kelly a283053408 Remove obsolete MSVC check from pragma guard
git grep -h -B1 "^#\s*pragma once" | grep -v pragma | sort | uniq

is now clean.

[SVN r85952]
2013-09-26 13:02:51 +00:00
Stephen Kelly 84bdf52f3f Variant: Remove use of obsolete macros.
[SVN r85951]
2013-09-26 09:48:32 +00:00
Stephen Kelly 0e0e0604e4 Variant: Remove obsolete MSVC version checks.
[SVN r85950]
2013-09-26 09:48:16 +00:00
Stephen Kelly 1bf7b791fd Variant: Remove obsolete eti workaround.
[SVN r85949]
2013-09-26 09:47:54 +00:00
Antony Polukhin 97e5305d6b Fix MSVC warning in Boost.Variant (refs #3020)
[SVN r85928]
2013-09-26 07:46:25 +00:00
Antony Polukhin 791f267dda Optimize and fix ambiguity of move_swap in Boost.Variant (refs #2839)
Fix GCC-4.8+ warning in variant_reference_test.cpp

[SVN r85927]
2013-09-26 07:29:25 +00:00
Antony Polukhin d8180bc3a8 Add experimental variadic templates support to Boost.Variant, enable usage of variadic version for gcc-4.8, clang-3.0 and later compilers (refs #9163)
With this patch size of a binary siginificantly reduced (up to two times)

[SVN r85899]
2013-09-25 11:54:19 +00:00
Stephen Kelly a1b3867b3a Remove use of obsolete BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE{,_SPEC} macro.
[SVN r85896]
2013-09-25 10:29:44 +00:00
Stephen Kelly 4254803c98 Remove use of obsolete BOOST_EXPLICIT_TEMPLATE_TYPE{,_SPEC} macros.
[SVN r85894]
2013-09-25 10:28:56 +00:00
Antony Polukhin 6db57f7d6b Fix unreachable code warning, thanks 'hvemha' for providing it (refs #8665)
[SVN r85876]
2013-09-25 07:13:57 +00:00
Antony Polukhin 1b57cf1ade Fix issue with const rvalue references in Boost.Variant (refs #8988)
[SVN r85315]
2013-08-12 12:00:13 +00:00
Antony Polukhin f9d2d9f9d9 Get rid of Boost.Variant hand written non-usable move emulation and use Boost.Move instead (refs #7601). This commit does not make Boost.Variant use move emulated assignments in all situations, but at least removes duplicate/non-working code and makes sure that Boost.Variant is able to work with boost::move (one step closer to full support of rvalue references emulations).
[SVN r85159]
2013-07-25 13:19:50 +00:00
Antony Polukhin 86165b88e3 Temporary disable noexcept detection for move assignment for Boost.Variant (exception specification detection for assignment requires call to is_nothrow_move_assignable for each type. But GCC 4.6 fails to do that and complains about incomplete types ) (refs #7911)
[SVN r85089]
2013-07-20 17:20:02 +00:00
Antony Polukhin e8e060416c Fix test case (refs #8772)
[SVN r85087]
2013-07-20 15:32:31 +00:00
Antony Polukhin eebda61e78 Make Boost.Variant work on exception-disabled environments (refs #8717)
[SVN r85081]
2013-07-19 11:40:06 +00:00
Antony Polukhin a3eb4ddd48 Fix compilation of Boost.Variants move assignment for situations when one of the variant template classes has nothrow copy constructor and throwing move constructor (refs #8772)
[SVN r85080]
2013-07-19 07:52:40 +00:00
Antony Polukhin e6014a3e21 Added code (and tests) to mark move constructors and move assignemnt of Boost.Variant as noexcept if possible (refs #7911)
[SVN r85079]
2013-07-19 07:43:03 +00:00
Antony Polukhin 3d44c5b695 Workaround for GCC bug (refs #8651)
[SVN r84683]
2013-06-08 07:32:22 +00:00
Antony Polukhin f5f3769cd4 Update Boost.Variant documentation, add info about multivisitors (refs #8459)
[SVN r84227]
2013-05-10 16:30:12 +00:00
Antony Polukhin 64673bf9df Added one more test for multivisitors that will be used as an example in documentation (refs #8459)
[SVN r84224]
2013-05-10 14:08:49 +00:00
Antony Polukhin bc54cab94e Multivisitors commit (refs #8459)
[SVN r84112]
2013-05-02 16:45:58 +00:00
Antony Polukhin 6c26dd544d Update docs of Boost.Variant. Add advice about recursive_wrapper performance (refs #7718)
[SVN r84104]
2013-05-02 08:39:34 +00:00
Antony Polukhin efd81f5a2a Use is_nothrow_move_constructible from Boost.TypeTraits in Boost.Variant (refs #8296)
[SVN r83458]
2013-03-16 10:50:44 +00:00
Antony Polukhin 7c2576948d Refs #7718 :
Workaroung GCC-4.7.2 internal compiler error
More functions marked with BOOST_NOEXCEPT
Added move constructors and move assignment operators to recursive_wrapper

[SVN r81652]
2012-12-01 15:32:07 +00:00
Marshall Clow b173a982e9 Fix a couple more deprecated macros in Boost.Variant
[SVN r81626]
2012-11-29 17:03:40 +00:00
Antony Polukhin d1376d9783 Basic rvalues and C++11 support part 2 (refs #7718 , all bugs from patch were fixed)
[SVN r81617]
2012-11-28 19:20:19 +00:00
Marshall Clow 21b9130e3a Remove usage of deprecated macros
[SVN r81472]
2012-11-22 06:13:20 +00:00
Antony Polukhin f398fb9b2a Added basic rvalue support and marked some functions with BOOST_NOEXCEPT (#refs #7620)
[SVN r81293]
2012-11-11 08:04:55 +00:00
Steven Watanabe 78d52b15cc Make sure that variants with more than 20 types work.
[SVN r77098]
2012-02-23 01:14:13 +00:00
Antony Polukhin 2bef470d77 Fixes #6163 (hash function for variant added)
[SVN r75606]
2011-11-22 16:05:44 +00:00
Steven Watanabe f9e03b6053 Supress warnings from variant. Refs #4666.
[SVN r71083]
2011-04-07 15:35:56 +00:00
Steven Watanabe e5547f95bc Avoid a quadratic number of template instantations when using the general case implementation of assignment (with backup storage). This significantly improves compile times for variants with a large number of variant types. See the thread starting at http://lists.boost.org/boost-users/2011/01/65416.php.
[SVN r67798]
2011-01-08 22:44:06 +00:00
Steven Watanabe 0aae21dc6e Make operator() const. Fixes #4967
[SVN r67605]
2011-01-03 05:06:52 +00:00
Steven Watanabe 3f255f9108 Avoid error instantiating map with recursive_variant_. Disable ADL to make instantiation less likely. Fixes #4584.
[SVN r67604]
2011-01-03 04:57:44 +00:00
Daniel James 9f5f65ab9b Detab some jamfiles.
[SVN r63343]
2010-06-26 12:10:47 +00:00
Daniel James 3e99de6129 Update various libraries' documentation build.
Mostly to use the images and css files under doc/src instead of
doc/html, usually be deleting the settings in order to use the defaults.
Also add 'boost.root' to some builds in order to fix links which rely on
it.

[SVN r63146]
2010-06-20 18:00:48 +00:00
Steven Watanabe 40614b7c73 Use the least common multiple of alignments instead of the max. Fixes #993
[SVN r62754]
2010-06-10 18:45:14 +00:00
Steven Watanabe 392fab2f89 Make sure that recursive_variant_ substitution works in all cases. Fixes #1654
[SVN r62753]
2010-06-10 18:16:19 +00:00
Steven Watanabe 7afab43f31 Add missing #includes. Fixes #3515
[SVN r62698]
2010-06-09 23:41:38 +00:00
John Maddock 0110af77a4 Fix various Variant warnings.
Addresses issue #1507.

[SVN r57631]
2009-11-13 10:07:30 +00:00
Hartmut Kaiser 79f5d17b43 Variant: silenced a couple of MSVC warnings created during Spirit test runs
[SVN r57501]
2009-11-09 03:56:25 +00:00
Troy D. Straszheim fad89dadec rm cmake from trunk. I'm not entirely sure this is necessary to satisfy the inspect script, but I'm not taking any chances, and it is easy to put back
[SVN r56942]
2009-10-17 02:07:38 +00:00
Troy D. Straszheim 802f51fdc0 Copyrights on CMakeLists.txt to keep them from clogging up the inspect
reports.  This is essentially the same commit as r55095 on the release
branch.



[SVN r55159]
2009-07-26 00:49:56 +00:00
Daniel James 25da2b8de7 Add boost license info to documentation for a few libraries.
* Boost.Any: Kevlin Henney is in blanket-permission.txt
  * Boost.Variant: Eric Friedman and Itay Maman are both in blanket-permissions.txt
  * Boost.Concept: Idiana University, University of Notre Dame du Lac, Jeremy Siek,
    Lie-Quan Lee, Andrew Lumsdaine are all listed under blanket permissions.

  SGI and HP aren't so their license is left alone.

[SVN r55098]
2009-07-22 22:35:08 +00:00
Daniel James 5d727edcff Support BOOST_NO_TYPEID and BOOST_NO_IOSTREAM in Boost.Variant. Fixes #3051.
[SVN r53682]
2009-06-06 11:46:24 +00:00
Steven Watanabe 4d362457bb Replace v with operand in the tutorial. Fixes #1548
[SVN r53187]
2009-05-22 20:05:26 +00:00
John Maddock a8b1d0f5d0 Add PDF generation options to fix external links to point to the web site.
Added a few more Boostbook based libs that were missed first time around.
Fixed PDF naming issues.

[SVN r51284]
2009-02-17 10:05:58 +00:00
Michael A. Jackson f7be108ab5 Updating dependency information for modularized libraries.
[SVN r49628]
2008-11-07 17:05:27 +00:00
Michael A. Jackson 0fe5e2e874 Updating CMake files to latest trunk. Added dependency information for regression tests and a few new macros for internal use.
[SVN r49627]
2008-11-07 17:02:56 +00:00
Michael A. Jackson 7df722ef6e Continuing merge of CMake build system files into trunk with the encouragement of Doug Gregor
[SVN r49510]
2008-11-01 13:15:41 +00:00
K. Noel Belcourt 25e12b7428 Fixes #965
Patched the XML and will check to ensure the html
page reflects this change.



[SVN r42989]
2008-01-26 23:06:24 +00:00
Beman Dawes 769ecfba29 // Add or correct comment identifying Boost library this header is associated with.
[SVN r41173]
2007-11-17 20:13:16 +00:00
Vladimir Prus ba9d0e00d7 Remove V1 Jamfiles
[SVN r38516]
2007-08-08 19:02:26 +00:00
Gennaro Prota deaf338bd4 fixed typos reported in http://bugs.debian.org/378016
[SVN r34629]
2006-07-20 13:15:25 +00:00
Eric Friedman 126fb460ce Fix to make direct assignment actually possible.
[SVN r34174]
2006-06-05 02:00:58 +00:00
106 changed files with 6762 additions and 2564 deletions
+11
View File
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
+168
View File
@@ -0,0 +1,168 @@
name: CI
on:
pull_request:
push:
branches:
- master
- develop
- feature/**
env:
UBSAN_OPTIONS: print_stacktrace=1
jobs:
posix:
strategy:
fail-fast: false
matrix:
include:
- toolset: gcc-12
cxxstd: "03,11,14,17,2a"
os: ubuntu-22.04
cxxflags: "cxxflags=--coverage -fsanitize=address,leak,undefined -fno-sanitize-recover=undefined"
linkflags: "linkflags=--coverage -lasan -lubsan"
gcov_tool: "gcov-12"
launcher: "testing.launcher=LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.8"
- toolset: gcc-11
cxxstd: "03,11,14,17,2a"
os: ubuntu-22.04
cxxflags: "cxxflags=--coverage -fsanitize=address,leak,undefined -fno-sanitize-recover=undefined"
linkflags: "linkflags=--coverage -lasan -lubsan"
gcov_tool: "gcov-11"
launcher: "testing.launcher=LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.7"
- toolset: clang
compiler: clang++
cxxstd: "03,11,14,17,2a"
os: ubuntu-24.04
cxxflags: "cxxflags=-fsanitize=address,undefined,integer -fno-sanitize-recover=undefined"
linkflags: "linkflags=-fsanitize=address,undefined,integer"
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v6
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 10 https://github.com/boostorg/boost.git boost-root
cd boost-root
git submodule update --init --depth 10 --jobs 2 tools/boostdep tools/inspect libs/filesystem
python tools/boostdep/depinst/depinst.py --git_args "--depth 10 --jobs 3" filesystem
rm -rf libs/$LIBRARY/*
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
python tools/boostdep/depinst/depinst.py --include benchmark --include example --include examples --include tools --git_args "--depth 10 --jobs 3" $LIBRARY
./bootstrap.sh
./b2 -d0 headers
./b2 -j4 variant=debug tools/inspect
- name: Run tests
run: |
cd ../boost-root
./b2 -j3 libs/$LIBRARY/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} variant=debug,release "${{matrix.cxxflags}}" "${{matrix.linkflags}}" "${{matrix.launcher}}"
dist/bin/inspect libs/$LIBRARY
- name: Prepare coverage data
if: matrix.gcov_tool
run: |
mkdir -p $GITHUB_WORKSPACE/coveralls
echo -e "#!/bin/bash\nexec ${{matrix.gcov_tool}} \"\$@\"" > $GITHUB_WORKSPACE/coveralls/gcov_wrapper.sh
chmod +x $GITHUB_WORKSPACE/coveralls/gcov_wrapper.sh
wget https://github.com/linux-test-project/lcov/archive/v1.16.zip
unzip v1.16.zip
LCOV="`pwd`/lcov-1.16/bin/lcov --gcov-tool $GITHUB_WORKSPACE/coveralls/gcov_wrapper.sh"
echo "$LCOV --directory ../boost-root/bin.v2/libs/$LIBRARY/ --base-directory `pwd`/libs/$LIBRARY/test --capture --output-file $GITHUB_WORKSPACE/coveralls/coverage.info"
$LCOV --directory ../boost-root/bin.v2/libs/$LIBRARY/ --base-directory ../boost-root/ --capture --output-file $GITHUB_WORKSPACE/coveralls/coverage.info
$LCOV --remove $GITHUB_WORKSPACE/coveralls/coverage.info "/usr*" "*/$LIBRARY/test/*" ${{matrix.ignore_coverage}} "*/$LIBRARY/tests/*" "*/$LIBRARY/examples/*" "*/$LIBRARY/example/*" -o $GITHUB_WORKSPACE/coveralls/coverage.info
cd ../boost-root
OTHER_LIBS=`grep "submodule .*" .gitmodules | sed 's/\[submodule\ "\(.*\)"\]/"\*\/boost\/\1\.hpp" "\*\/boost\/\1\/\*"/g'| sed "/\"\*\/boost\/$LIBRARY\/\*\"/d" | sed ':a;N;$!ba;s/\n/ /g'`
echo $OTHER_LIBS
eval "$LCOV --remove $GITHUB_WORKSPACE/coveralls/coverage.info $OTHER_LIBS -o $GITHUB_WORKSPACE/coveralls/coverage.info"
- name: Coveralls
uses: coverallsapp/github-action@master
if: matrix.gcov_tool
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./coveralls/coverage.info
parallel: true
windows:
strategy:
fail-fast: false
matrix:
include:
- toolset: msvc
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2022
- toolset: msvc
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2025
- toolset: gcc
cxxstd: "03,11,14,17,2a"
addrmd: 64
os: windows-2025
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v6
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 10 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --include benchmark --include example --include examples --include tools --git_args "--jobs 3" %LIBRARY%
cmd /c bootstrap
b2 -d0 headers
- name: Run tests
shell: cmd
run: |
cd ../boost-root
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release
finish:
needs: posix
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
+27
View File
@@ -0,0 +1,27 @@
# Copyright 2019 Mike Dev
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required( VERSION 3.5...3.20 )
project( boost_variant VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX )
add_library( boost_variant INTERFACE )
add_library( Boost::variant ALIAS boost_variant )
target_include_directories( boost_variant INTERFACE include )
target_link_libraries( boost_variant
INTERFACE
Boost::assert
Boost::config
Boost::container_hash
Boost::core
Boost::detail
Boost::integer
Boost::mpl
Boost::preprocessor
Boost::throw_exception
Boost::type_index
Boost::type_traits
Boost::utility
)
+16
View File
@@ -0,0 +1,16 @@
# [Boost.Variant](https://boost.org/libs/variant)
Boost.Variant, part of collection of the [Boost C++ Libraries](https://github.com/boostorg). It is a safe, generic, stack-based discriminated union container, offering a simple solution for manipulating an object from a heterogeneous set of types in a uniform manner.
### Test results
@ | Build | Tests coverage | More info
----------------|-------------- | -------------- |-----------
Develop branch: | [![CI](https://github.com/boostorg/variant/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/boostorg/variant/actions/workflows/ci.yml) [![Build status](https://ci.appveyor.com/api/projects/status/bijfdoy7byfgc6e2/branch/develop?svg=true)](https://ci.appveyor.com/project/apolukhin/variant-ykfti/branch/develop) | [![Coverage Status](https://coveralls.io/repos/boostorg/variant/badge.png?branch=develop)](https://coveralls.io/r/apolukhin/variant?branch=develop) | [details...](https://regression.boost.io/develop/developer/variant.html)
Master branch: | [![CI](https://github.com/boostorg/variant/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/boostorg/variant/actions/workflows/ci.yml) [![Build status](https://ci.appveyor.com/api/projects/status/bijfdoy7byfgc6e2/branch/master?svg=true)](https://ci.appveyor.com/project/apolukhin/variant-ykfti/branch/master) | [![Coverage Status](https://coveralls.io/repos/boostorg/variant/badge.png?branch=master)](https://coveralls.io/r/apolukhin/variant?branch=master) | [details...](https://regression.boost.io/master/developer/variant.html)
[Latest developer documentation](https://www.boost.org/doc/libs/develop/doc/html/variant.html)
### License
Distributed under the [Boost Software License, Version 1.0](https://boost.org/LICENSE_1_0.txt).
+34
View File
@@ -0,0 +1,34 @@
# Copyright René Ferdinand Rivera Morell 2023-2024
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
require-b2 5.2 ;
constant boost_dependencies :
/boost/assert//boost_assert
/boost/config//boost_config
/boost/container_hash//boost_container_hash
/boost/core//boost_core
/boost/detail//boost_detail
/boost/integer//boost_integer
/boost/mpl//boost_mpl
/boost/preprocessor//boost_preprocessor
/boost/throw_exception//boost_throw_exception
/boost/type_index//boost_type_index
/boost/type_traits//boost_type_traits
/boost/utility//boost_utility ;
project /boost/variant
: common-requirements
<include>include
;
explicit
[ alias boost_variant : : : : <library>$(boost_dependencies) ]
[ alias all : boost_variant test ]
;
call-if : boost-library variant
;
+19 -1
View File
@@ -1,4 +1,13 @@
project boost/doc ;
# Boost.Variant Library doc Jamfile
#
# Copyright (C) 2003, Eric Friedman, Itay Maman.
#
# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
project variant/doc ;
import boostbook : boostbook ;
boostbook variant-doc
@@ -9,3 +18,12 @@ boostbook variant-doc
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
;
###############################################################################
alias boostdoc
: variant.xml
:
:
: ;
explicit boostdoc ;
alias boostrelease ;
explicit boostrelease ;
+7 -1
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<section id="variant.refs">
<title>References</title>
@@ -109,4 +115,4 @@
2002.
</para>
</section>
</section>
+7 -24
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<section id="variant.design">
<title>Design Overview</title>
@@ -270,29 +276,6 @@
</para>
<para><emphasis role="bold">Caveat</emphasis>: On most platforms, the
<libraryname>Type Traits</libraryname> templates
<code>has_nothrow_copy</code> and <code>has_nothrow_constructor</code>
by default return <code>false</code> for all <code>class</code> and
<code>struct</code> types. It is necessary therefore to provide
specializations of these templates as appropriate for user-defined
types, as demonstrated in the following:
<programlisting>// ...in your code (at file scope)...
namespace boost {
template &lt;&gt;
struct <classname>has_nothrow_copy</classname>&lt; myUDT &gt;
: <classname>mpl::true_</classname>
{
};
}
</programlisting>
</para>
<para><emphasis role="bold">Implementation Note</emphasis>: So as to make
the behavior of <code>variant</code> more predictable in the aftermath
of an exception, the current implementation prefers to default-construct
@@ -324,4 +307,4 @@ namespace boost {
</section>
</section>
</section>
+7 -1
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<section id="variant.intro">
<title>Introduction</title>
@@ -132,4 +138,4 @@ int main()
</section>
</section>
</section>
+7 -1
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<section id="variant.misc">
<title>Miscellaneous Notes</title>
@@ -232,4 +238,4 @@ interface, and implementation of the library.</para>
</section>
</section>
</section>
+120 -24
View File
@@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Copyright 2013-2026 Antony Polukhin.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<header name="boost/variant/apply_visitor.hpp">
<namespace name="boost">
<class name="apply_visitor_delayed_t">
@@ -14,6 +21,9 @@
<simpara>See the &quot;visitor-only&quot; form of
<code><functionname>apply_visitor</functionname></code> for a simple
way to create <code>apply_visitor_delayed_t</code> objects.</simpara>
<simpara>See <code><classname>apply_visitor_delayed_cpp14_t</classname></code>
which is used on C++14 compatible compilers when <code>Visitor</code> has no
<code>result_type</code> typedef.</simpara>
</description>
<template>
@@ -37,6 +47,18 @@
<method-group name="function object interface">
<overloaded-method name="operator()">
<signature>
<template>
<template-type-parameter name="... Variant"/>
</template>
<type>result_type</type>
<parameter name="operand">
<paramtype>Variant&amp;...</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="Variant"/>
@@ -72,7 +94,63 @@
</overloaded-method>
</method-group>
</class>
<class name="apply_visitor_delayed_cpp14_t">
<purpose>Adapts a visitor for use as a function object.</purpose>
<description>
<simpara>Adapts the function given at construction for use as a
function object. This is useful, for example, when one needs to
operate on each element of a sequence of variant objects using a
standard library algorithm such as
<code>std::for_each</code>.</simpara>
<simpara>See the &quot;visitor-only&quot; form of
<code><functionname>apply_visitor</functionname></code> for a simple
way to create <code>apply_visitor_delayed_t</code> objects.</simpara>
<simpara>See <code><classname>apply_visitor_delayed_t</classname></code>
which is used when <code>Visitor</code> has <code>result_type</code>
typedef.</simpara>
<simpara>Available only if
compiler supports <code>decltype(auto)</code> and <code>decltype(some-expression)</code>.</simpara>
</description>
<template>
<template-type-parameter name="Visitor"/>
</template>
<constructor specifiers="explicit">
<parameter name="visitor">
<paramtype>Visitor &amp;</paramtype>
</parameter>
<effects>
<simpara>Constructs the function object with the given
visitor.</simpara>
</effects>
</constructor>
<method-group name="function object interface">
<overloaded-method name="operator()">
<signature>
<template>
<template-type-parameter name="... Variant"/>
</template>
<type>decltype(auto)</type>
<parameter name="operand">
<paramtype>Variant&amp;...</paramtype>
</parameter>
</signature>
<purpose>Function call operator.</purpose>
<description>
<simpara>Invokes
<code><functionname>apply_visitor</functionname></code> on the
stored visitor using the given operands.</simpara>
</description>
</overloaded-method>
</method-group>
</class>
<overloaded-function name="apply_visitor">
<signature>
<template>
@@ -86,10 +164,10 @@
<paramtype>Visitor &amp;</paramtype>
</parameter>
<parameter name="operand">
<paramtype>Variant &amp;</paramtype>
<paramtype>Variant&amp;&amp;</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="Visitor"/>
@@ -102,7 +180,7 @@
<paramtype>const Visitor &amp;</paramtype>
</parameter>
<parameter name="operand">
<paramtype>Variant &amp;</paramtype>
<paramtype>Variant&amp;&amp;</paramtype>
</parameter>
</signature>
@@ -113,16 +191,16 @@
<template-type-parameter name="Variant2"/>
</template>
<type>typename BinaryVisitor::result_type</type>
<type>typename BinaryVisitor::result_type OR decltype(auto)</type>
<parameter name="visitor">
<paramtype>BinaryVisitor &amp;</paramtype>
</parameter>
<parameter name="operand1">
<paramtype>Variant1 &amp;</paramtype>
<paramtype>Variant1&amp;&amp;</paramtype>
</parameter>
<parameter name="operand2">
<paramtype>Variant2 &amp;</paramtype>
<paramtype>Variant2&amp;&amp;</paramtype>
</parameter>
</signature>
@@ -133,16 +211,16 @@
<template-type-parameter name="Variant2"/>
</template>
<type>typename BinaryVisitor::result_type</type>
<type>typename BinaryVisitor::result_type OR decltype(auto)</type>
<parameter name="visitor">
<paramtype>const BinaryVisitor &amp;</paramtype>
</parameter>
<parameter name="operand1">
<paramtype>Variant1 &amp;</paramtype>
<paramtype>Variant1&amp;&amp;</paramtype>
</parameter>
<parameter name="operand2">
<paramtype>Variant2 &amp;</paramtype>
<paramtype>Variant2&amp;&amp;</paramtype>
</parameter>
</signature>
@@ -154,19 +232,19 @@
<template-type-parameter name="Variant3"/>
</template>
<type>typename MultiVisitor::result_type</type>
<type>typename MultiVisitor::result_type OR decltype(auto)</type>
<parameter name="visitor">
<paramtype>MultiVisitor &amp;</paramtype>
</parameter>
<parameter name="operand1">
<paramtype>Variant1 &amp;</paramtype>
<paramtype>Variant1&amp;&amp;</paramtype>
</parameter>
<parameter name="operand2">
<paramtype>Variant2 &amp;</paramtype>
<paramtype>Variant2&amp;&amp;</paramtype>
</parameter>
<parameter name="operand3">
<paramtype>Variant3 &amp;</paramtype>
<paramtype>Variant3&amp;&amp;</paramtype>
</parameter>
<parameter name="other_operands">
<paramtype>...</paramtype>
@@ -181,19 +259,19 @@
<template-type-parameter name="Variant3"/>
</template>
<type>typename MultiVisitor::result_type</type>
<type>typename MultiVisitor::result_type OR decltype(auto)</type>
<parameter name="visitor">
<paramtype>const MultiVisitor &amp;</paramtype>
</parameter>
<parameter name="operand1">
<paramtype>Variant1 &amp;</paramtype>
<paramtype>Variant1&amp;&amp;</paramtype>
</parameter>
<parameter name="operand2">
<paramtype>Variant2 &amp;</paramtype>
<paramtype>Variant2&amp;&amp;</paramtype>
</parameter>
<parameter name="operand3">
<paramtype>Variant3 &amp;</paramtype>
<paramtype>Variant3&amp;&amp;</paramtype>
</parameter>
<parameter name="other_operands">
<paramtype>...</paramtype>
@@ -212,6 +290,19 @@
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="Visitor"/>
</template>
<type><classname>apply_visitor_delayed_cpp14_t</classname>&lt;Visitor&gt;</type>
<parameter name="visitor">
<paramtype>Visitor &amp;</paramtype>
</parameter>
</signature>
<purpose>
<simpara>Allows compile-time checked type-safe application of the
given visitor to the content of the given variant, ensuring that all
@@ -221,7 +312,8 @@
<description>
<simpara>The behavior of <code>apply_visitor</code> is dependent on
the number of arguments on which it operates (i.e., other than the
visitor). The function behaves as follows:
visitor). If your compiler does not support the rvalue references or reference qualifiers then all the
forwarding references from above degrade to non const lvalue reference. The function behaves as follows:
<itemizedlist>
<listitem>Overloads accepting one operand invoke the unary function
@@ -236,13 +328,17 @@
<listitem>Overloads accepting three or more operands invoke the
function call operator of the given visitor on the content of
the given <code><classname>variant</classname></code>
operands. Maximum amount of parameters controlled by
operands. Maximum amount of parameters controlled by
<code><emphasis role="bold"><macroname>BOOST_VARAINT_MAX_MULTIVIZITOR_PARAMS</macroname></emphasis></code>
macro. Those functions are actually defined in <xref linkend="header.boost.variant.multivisitors_hpp"/>.</listitem>
macro. Those functions are actually defined in a header <code>boost/variant/multivisitors.hpp</code>
(See <xref linkend="header.boost.variant.multivisitors_hpp"/>). That header must be manually included
if multi visitors are meant for use.</listitem>
<listitem>The overload accepting only a visitor returns a
<classname alt="boost::apply_visitor_delayed_t">generic function object</classname>
that accepts either one or two arguments and invokes
<listitem>The overloads accepting only a visitor return a
<classname alt="boost::apply_visitor_delayed_t">C++03 compatible generic function object</classname>
or
<classname alt="boost::apply_visitor_delayed_cpp14_t">C++14 compatible generic function object</classname>
that accepts either one, two or arbitrary count of arguments and invoke
<code><functionname>apply_visitor</functionname></code> using
these arguments and <code>visitor</code>, thus behaving as
specified above. (This behavior is particularly useful, for
+7 -1
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<header name="boost/variant/bad_visit.hpp">
<namespace name="boost">
@@ -20,4 +26,4 @@
</class>
</namespace>
</header>
</header>
+25 -3
View File
@@ -1,4 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<section id="variant.concepts">
<title>Concepts</title>
@@ -74,7 +82,9 @@
<listitem>Must allow invocation as a function by overloading
<code>operator()</code>, unambiguously accepting any value of type
<code>T</code>.</listitem>
<listitem>Must expose inner type <code>result_type</code>. (See
<listitem>Must expose inner type <code>result_type</code>. C++14 compatible compilers
could detect <code>result_type</code> automatically, but will stick to
<code>result_type</code> if it is defined. (See
<code><functionname>boost::visitor_ptr</functionname></code> for a
solution to using functions as visitors.)</listitem>
<listitem>If <code>result_type</code> is not <code>void</code>, then
@@ -123,6 +133,18 @@ public:
}
};</programlisting>
<para>C++14 compatible compilers detect <code>result_type</code> automatically:</para>
<programlisting>
<classname>boost::variant</classname>&lt;int, float&gt; v;
// ...
<functionname>boost::apply_visitor</functionname>(
[](auto val) { return std::to_string(val); },
v
);
</programlisting>
</section>
</section>
@@ -151,4 +173,4 @@ public:
</itemizedlist>
</section>
</section>
</section>
+227 -7
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<header name="boost/variant/get.hpp">
<namespace name="boost">
@@ -10,17 +16,17 @@
</inherit>
<purpose>
<simpara>The exception thrown in the event of a failed application of
<code><functionname>boost::get</functionname></code> on the given
<simpara>The exception thrown in the event of a failed application of
<code><functionname>boost::get</functionname></code> on the given
operand value.</simpara>
</purpose>
<method name="what" specifiers="virtual" cv="const">
<type>const char *</type>
<method name="what" specifiers="virtual" cv="const">
<type>const char *</type>
</method>
</class>
<overloaded-function name="get">
<overloaded-function name="relaxed_get">
<signature>
<template>
<template-type-parameter name="U"/>
@@ -52,7 +58,7 @@
<paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
@@ -85,9 +91,27 @@
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>U &amp;&amp;</type>
<parameter name="operand">
<paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;&amp;</paramtype>
</parameter>
</signature>
<purpose>
<simpara>Retrieves a value of a specified type from a given
<code><classname>variant</classname></code>.</simpara>
<code><classname>variant</classname></code>. </simpara>
<simpara>Unlike <functionname>strict_get</functionname> does not assert at compile time
that type <code>U</code> is one of the types that can be stored in variant.</simpara>
</purpose>
<description>
@@ -96,6 +120,11 @@
<code><classname>variant</classname></code>. The function succeeds
only if the content is of the specified type <code>U</code>, with
failure indicated as described below.</simpara>
<simpara><emphasis role="bold">Recomendation</emphasis>: Use
<functionname>get</functionname> or <functionname>strict_get</functionname> in new code.
<functionname>strict_get</functionname>
provides more compile time checks and its behavior is closer to <code>std::get</code>
from C++ Standard Library.</simpara>
<simpara><emphasis role="bold">Warning</emphasis>: After either
<code>operand</code> or its content is destroyed (e.g., when the
given <code><classname>variant</classname></code> is assigned a
@@ -142,5 +171,196 @@
</rationale>
</overloaded-function>
<overloaded-function name="strict_get">
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>U *</type>
<parameter name="operand">
<paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>const U *</type>
<parameter name="operand">
<paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>U &amp;</type>
<parameter name="operand">
<paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>const U &amp;</type>
<parameter name="operand">
<paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>U &amp;&amp;</type>
<parameter name="operand">
<paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;&amp;</paramtype>
</parameter>
</signature>
<purpose>
<simpara>Retrieves a value of a specified type from a given
<code><classname>variant</classname></code>.</simpara>
</purpose>
<description>
<simpara>Acts exactly like <functionname>relaxed_get</functionname> but does a compile time check
that type <code>U</code> is one of the types that can be stored in variant.</simpara>
</description>
</overloaded-function>
<overloaded-function name="get">
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>U *</type>
<parameter name="operand">
<paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>const U *</type>
<parameter name="operand">
<paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>U &amp;</type>
<parameter name="operand">
<paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>const U &amp;</type>
<parameter name="operand">
<paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>U &amp;&amp;</type>
<parameter name="operand">
<paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;&amp;</paramtype>
</parameter>
</signature>
<purpose>
<simpara>Retrieves a value of a specified type from a given
<code><classname>variant</classname></code>.</simpara>
</purpose>
<description>
<simpara>Evaluates to <functionname>strict_get</functionname> if <code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>
is not defined. If <code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>
is defined then evaluates to <functionname>relaxed_get</functionname>. </simpara>
<simpara><emphasis role="bold">Recomendation</emphasis>: Use
<functionname>get</functionname> in new code without defining
<code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>. In that way <functionname>get</functionname>
provides more compile time checks and its behavior is closer to <code>std::get</code>
from C++ Standard Library.</simpara>
</description>
</overloaded-function>
</namespace>
</header>
+14 -22
View File
@@ -1,26 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2013-2026 Antony Polukhin.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<header name="boost/variant/multivisitors.hpp">
<using-namespace name="boost"/>
<para>Provides declarations of <functionname>apply_visitor</functionname> for three or more
<code><classname>variant</classname></code> parameters.</para>
<macro name="BOOST_VARAINT_MAX_MULTIVIZITOR_PARAMS">
<purpose>
<simpara>Controls maximum amount of <code><classname>variant</classname></code>
parameters for multi visistors. </simpara>
</purpose>
<description>
<para><emphasis role="bold">Note</emphasis>: Default amount is 4. Define it
to bigger value before including &lt;boost/variant/multivisitors.hpp&gt; to
increase maximum amount of <code><classname>variant</classname></code>
parameters for <functionname>apply_visitor</functionname>.</para>
</description>
</macro>
<namespace name="boost">
<overloaded-function name="apply_visitor /*three or more variant parameters*/">
<description>
@@ -38,19 +30,19 @@
<template-type-parameter name="Variant3"/>
</template>
<type>typename MultiVisitor::result_type</type>
<type>typename MultiVisitor::result_type OR decltype(auto)</type>
<parameter name="visitor">
<paramtype>MultiVisitor &amp;</paramtype>
</parameter>
<parameter name="operand1">
<paramtype>Variant1 &amp;</paramtype>
<paramtype>Variant1&amp;&amp;</paramtype>
</parameter>
<parameter name="operand2">
<paramtype>Variant2 &amp;</paramtype>
<paramtype>Variant2&amp;&amp;</paramtype>
</parameter>
<parameter name="operand3">
<paramtype>Variant3 &amp;</paramtype>
<paramtype>Variant3&amp;&amp;</paramtype>
</parameter>
<parameter name="other_operands">
<paramtype>...</paramtype>
@@ -65,19 +57,19 @@
<template-type-parameter name="Variant3"/>
</template>
<type>typename MultiVisitor::result_type</type>
<type>typename MultiVisitor::result_type OR decltype(auto)</type>
<parameter name="visitor">
<paramtype>const MultiVisitor &amp;</paramtype>
</parameter>
<parameter name="operand1">
<paramtype>Variant1 &amp;</paramtype>
<paramtype>Variant1&amp;&amp;</paramtype>
</parameter>
<parameter name="operand2">
<paramtype>Variant2 &amp;</paramtype>
<paramtype>Variant2&amp;&amp;</paramtype>
</parameter>
<parameter name="operand3">
<paramtype>Variant3 &amp;</paramtype>
<paramtype>Variant3&amp;&amp;</paramtype>
</parameter>
<parameter name="other_operands">
<paramtype>...</paramtype>
+326
View File
@@ -0,0 +1,326 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2013-2026 Antony Polukhin.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<header name="boost/variant/polymorphic_get.hpp">
<namespace name="boost">
<class name="bad_polymorphic_get">
<inherit access="public">
<classname>boost::bad_get</classname>
</inherit>
<purpose>
<simpara>The exception thrown in the event of a failed application of
<code><functionname>boost::polymorphic_get</functionname></code> on the given
operand value.</simpara>
</purpose>
<method name="what" specifiers="virtual" cv="const">
<type>const char *</type>
</method>
</class>
<overloaded-function name="polymorphic_relaxed_get">
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>U *</type>
<parameter name="operand">
<paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>const U *</type>
<parameter name="operand">
<paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>U &amp;</type>
<parameter name="operand">
<paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>const U &amp;</type>
<parameter name="operand">
<paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
</parameter>
</signature>
<purpose>
<simpara>Retrieves a value of a specified type from a given
<code><classname>variant</classname></code>.</simpara>
<simpara>Unlike <functionname>polymorphic_strict_get</functionname> does not assert at compile time
that type <code>U</code> is one of the types that can be stored in variant.</simpara>
</purpose>
<description>
<simpara>The <code>polymorphic_get</code> function allows run-time checked,
type-safe retrieval of the content of the given
<code><classname>variant</classname></code>. The function succeeds
only if the content is of the specified type <code>U</code> or of type
derived from type <code>U</code>, with
failure indicated as described below.</simpara>
<simpara><emphasis role="bold">Recomendation</emphasis>: Use
<functionname>polymorphic_get</functionname> or <functionname>polymorphic_strict_get</functionname>
in new code.
<functionname>polymorphic_strict_get</functionname>
provides more compile time checks and its behavior is closer to <code>std::get</code>
from C++ Standard Library.</simpara>
<simpara><emphasis role="bold">Warning</emphasis>: After either
<code>operand</code> or its content is destroyed (e.g., when the
given <code><classname>variant</classname></code> is assigned a
value of different type), the returned reference is invalidated.
Thus, significant care and caution must be extended when handling
the returned reference.</simpara>
</description>
<notes>
<simpara>As part of its guarantee of type-safety, <code>polymorphic_get</code>
enforces <code>const</code>-correctness. Thus, the specified type
<code>U</code> must be <code>const</code>-qualified whenever
<code>operand</code> or its content is likewise
<code>const</code>-qualified. The converse, however, is not required:
that is, the specified type <code>U</code> may be
<code>const</code>-qualified even when <code>operand</code> and its
content are not.</simpara>
</notes>
<returns>
<simpara>If passed a pointer, <code>polymorphic_get</code> returns a pointer to
the value content if it is of the specified type <code>U</code> or of type
derived from type <code>U</code>;
otherwise, a null pointer is returned. If passed a reference,
<code>polymorphic_get</code> returns a reference to the value content if it is of
the specified type <code>U</code> or of type
derived from type <code>U</code>; otherwise, an exception is thrown
(see below).</simpara>
</returns>
<throws>
<simpara>Overloads taking a
<code><classname>variant</classname></code> pointer will not
throw; the overloads taking a
<code><classname>variant</classname></code> reference throw
<code><classname>bad_polymorphic_get</classname></code> if the content is not of
the specified type <code>U</code>or of type
derived from type <code>U</code>.</simpara>
</throws>
<rationale>
<simpara>While visitation via
<code><functionname>apply_visitor</functionname></code>
is generally preferred due to its greater safety, <code>polymorphic_get</code> may
may be more convenient in some cases due to its straightforward
usage.</simpara>
</rationale>
</overloaded-function>
<overloaded-function name="polymorphic_strict_get">
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>U *</type>
<parameter name="operand">
<paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>const U *</type>
<parameter name="operand">
<paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>U &amp;</type>
<parameter name="operand">
<paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>const U &amp;</type>
<parameter name="operand">
<paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
</parameter>
</signature>
<purpose>
<simpara>Retrieves a value of a specified type from a given
<code><classname>variant</classname></code>.</simpara>
</purpose>
<description>
<simpara>Acts exactly like <functionname>polymorphic_relaxed_get</functionname> but does a compile time check
that type <code>U</code> is one of the types that can be stored in variant.</simpara>
</description>
</overloaded-function>
<overloaded-function name="polymorphic_get">
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>U *</type>
<parameter name="operand">
<paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>const U *</type>
<parameter name="operand">
<paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; *</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>U &amp;</type>
<parameter name="operand">
<paramtype><classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
</parameter>
</signature>
<signature>
<template>
<template-type-parameter name="U"/>
<template-type-parameter name="T1"/>
<template-type-parameter name="T2"/>
<template-varargs/>
<template-type-parameter name="TN"/>
</template>
<type>const U &amp;</type>
<parameter name="operand">
<paramtype>const <classname>variant</classname>&lt;T1, T2, ..., TN&gt; &amp;</paramtype>
</parameter>
</signature>
<purpose>
<simpara>Retrieves a value of a specified type from a given
<code><classname>variant</classname></code>.</simpara>
</purpose>
<description>
<simpara>Evaluates to <functionname>polymorphic_strict_get</functionname>
if <code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>
is not defined. If <code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>
is defined then evaluates to <functionname>polymorphic_relaxed_get</functionname>. </simpara>
<simpara><emphasis role="bold">Recomendation</emphasis>: Use
<functionname>polymorphic_get</functionname> in new code without defining
<code>BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT</code>. In that way
<functionname>polymorphic_get</functionname>
provides more compile time checks and its behavior is closer to <code>std::get</code>
from C++ Standard Library.</simpara>
</description>
</overloaded-function>
</namespace>
</header>
+7 -6
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<header name="boost/variant/recursive_variant.hpp">
<namespace name="boost">
@@ -98,14 +104,9 @@
<listitem><code>Sequence</code> must meet the requirements of
<libraryname>MPL</libraryname>'s <emphasis>Sequence</emphasis>
concept.</listitem>
<listitem>Due to standard conformance problems in several compilers,
<code>make_recursive_variant_over</code> may not be supported on
your compiler. See
<code><macroname>BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT</macroname></code>
for more information.</listitem>
</itemizedlist>
</description>
</class>
</namespace>
</header>
</header>
+8 -2
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<header name="boost/variant/recursive_wrapper.hpp">
<namespace name="boost">
@@ -261,4 +267,4 @@
</class>
</namespace>
</header>
</header>
+7
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE library-reference PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<library-reference xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="concepts.xml"/>
@@ -19,6 +25,7 @@
<xi:include href="apply_visitor.xml"/>
<xi:include href="multivisitor.xml"/>
<xi:include href="get.xml"/>
<xi:include href="polymorphic_get.xml"/>
<xi:include href="bad_visit.xml"/>
<xi:include href="static_visitor.xml"/>
<xi:include href="visitor_ptr.xml"/>
+7 -1
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<header name="boost/variant/static_visitor.hpp">
<namespace name="boost">
@@ -28,4 +34,4 @@
</class>
</namespace>
</header>
</header>
+203 -13
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<header name="boost/variant/variant.hpp">
<namespace name="boost">
<class name="variant">
@@ -502,6 +508,12 @@
<method name="type" cv="const">
<type>const std::type_info &amp;</type>
<notes>
<simpara><code>boost::variant</code> usues Boost.TypeIndex library so actually
<code>const boost::typeindex::type_info &amp;</code> is returned.
This method is available even if RTTI is off.</simpara>
</notes>
<returns>
<simpara><code>typeid(x)</code>, where <code>x</code> is the the
content of <code>*this</code>.</simpara>
@@ -509,10 +521,6 @@
<throws>Will not throw.</throws>
<notes>
<simpara>Not available when <code>BOOST_NO_TYPEID</code> is
defined.</simpara>
</notes>
</method>
</method-group>
@@ -528,7 +536,7 @@
<paramtype>const variant &amp;</paramtype>
</parameter>
</signature>
<signature cv="const">
<type>void</type>
<template>
@@ -554,14 +562,60 @@
</requires>
<returns>
<simpara><code>true</code> iff <code>which() == rhs.which()</code>
<simpara><code>true</code> if <code>which() == rhs.which()</code>
<emphasis>and</emphasis>
<code>content_this == content_rhs</code>, where
<code>content_this</code> is the content of <code>*this</code>
and <code>content_rhs</code> is the content of
<code>rhs</code>.</simpara>
</returns>
<throws>
<simpara>If <code>which() == rhs.which()</code> then may fail with
any exceptions arising from <code>operator==(T,T)</code>, where
<code>T</code> is the contained type of
<code>*this</code>.</simpara>
</throws>
</overloaded-method>
<overloaded-method name="operator!=" cv="const">
<purpose>InEquality comparison.</purpose>
<signature cv="const">
<type>bool</type>
<parameter name="rhs">
<paramtype>const variant &amp;</paramtype>
</parameter>
</signature>
<signature cv="const">
<type>void</type>
<template>
<template-type-parameter name="U"/>
</template>
<parameter>
<paramtype>const U &amp;</paramtype>
</parameter>
</signature>
<notes>
<simpara>The overload returning <code>void</code> exists only to
prohibit implicit conversion of the operator's right-hand side
to <code>variant</code>; thus, its use will (purposefully)
result in a compile-time error.</simpara>
</notes>
<requires>
<simpara>Every bounded type of the <code>variant</code> must
fulfill the requirements of the
<conceptname>EqualityComparable</conceptname>
concept.</simpara>
</requires>
<returns>
<simpara><code>true</code> if <code>!(*this == rhs)</code>.</simpara>
</returns>
<throws>
<simpara>If <code>which() == rhs.which()</code> then may fail with
any exceptions arising from <code>operator==(T,T)</code>, where
@@ -579,7 +633,7 @@
<paramtype>const variant &amp;</paramtype>
</parameter>
</signature>
<signature cv="const">
<type>void</type>
<template>
@@ -620,6 +674,147 @@
</throws>
</overloaded-method>
<overloaded-method name="operator&gt;">
<purpose>GreaterThan comparison.</purpose>
<signature cv="const">
<type>bool</type>
<parameter name="rhs">
<paramtype>const variant &amp;</paramtype>
</parameter>
</signature>
<signature cv="const">
<type>void</type>
<template>
<template-type-parameter name="U"/>
</template>
<parameter>
<paramtype>const U &amp;</paramtype>
</parameter>
</signature>
<notes>
<simpara>The overload returning <code>void</code> exists only to
prohibit implicit conversion of the operator's right-hand side
to <code>variant</code>; thus, its use will (purposefully)
result in a compile-time error.</simpara>
</notes>
<requires>
<simpara>Every bounded type of the <code>variant</code> must
fulfill the requirements of the
<conceptname>LessThanComparable</conceptname>
concept.</simpara>
</requires>
<returns>
<simpara>true if <code>rhs &lt; *this</code>.</simpara>
</returns>
<throws>
<simpara>May fail with
any exceptions arising from <code>operator&lt;(T,T)</code>,
where <code>T</code> is the contained type of
<code>*this</code>.</simpara>
</throws>
</overloaded-method>
<overloaded-method name="operator&lt;=">
<purpose>LessThan or Equal comparison.</purpose>
<signature cv="const">
<type>bool</type>
<parameter name="rhs">
<paramtype>const variant &amp;</paramtype>
</parameter>
</signature>
<signature cv="const">
<type>void</type>
<template>
<template-type-parameter name="U"/>
</template>
<parameter>
<paramtype>const U &amp;</paramtype>
</parameter>
</signature>
<notes>
<simpara>The overload returning <code>void</code> exists only to
prohibit implicit conversion of the operator's right-hand side
to <code>variant</code>; thus, its use will (purposefully)
result in a compile-time error.</simpara>
</notes>
<requires>
<simpara>Every bounded type of the <code>variant</code> must
fulfill the requirements of the
<conceptname>LessThanComparable</conceptname>
concept.</simpara>
</requires>
<returns>
<simpara>true if <code>!(*this > rhs)</code>.</simpara>
</returns>
<throws>
<simpara>May fail with
any exceptions arising from <code>operator&lt;(T,T)</code>,
where <code>T</code> is the contained type of
<code>*this</code>.</simpara>
</throws>
</overloaded-method>
<overloaded-method name="operator&gt;=">
<purpose>GreaterThan or Equal comparison.</purpose>
<signature cv="const">
<type>bool</type>
<parameter name="rhs">
<paramtype>const variant &amp;</paramtype>
</parameter>
</signature>
<signature cv="const">
<type>void</type>
<template>
<template-type-parameter name="U"/>
</template>
<parameter>
<paramtype>const U &amp;</paramtype>
</parameter>
</signature>
<notes>
<simpara>The overload returning <code>void</code> exists only to
prohibit implicit conversion of the operator's right-hand side
to <code>variant</code>; thus, its use will (purposefully)
result in a compile-time error.</simpara>
</notes>
<requires>
<simpara>Every bounded type of the <code>variant</code> must
fulfill the requirements of the
<conceptname>LessThanComparable</conceptname>
concept.</simpara>
</requires>
<returns>
<simpara>true if <code>!(*this &lt; lhs)</code>.</simpara>
</returns>
<throws>
<simpara>May fail with
any exceptions arising from <code>operator&lt;(T,T)</code>,
where <code>T</code> is the contained type of
<code>*this</code>.</simpara>
</throws>
</overloaded-method>
</method-group>
</class>
@@ -756,11 +951,6 @@
<listitem><code>Sequence</code> must meet the requirements of
<libraryname>MPL</libraryname>'s <emphasis>Sequence</emphasis>
concept.</listitem>
<listitem>Due to standard conformance problems in several compilers,
<code>make_variant_over</code> may not be supported on your
compiler. See
<code><macroname>BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT</macroname></code>
for more information.</listitem>
</itemizedlist>
</description>
</class>
+40 -42
View File
@@ -1,4 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Copyright 2016-2026 Antony Polukhin.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<header name="boost/variant/variant_fwd.hpp">
<using-namespace name="boost"/>
@@ -10,21 +19,6 @@
class templates and the <code>boost::recursive_variant_</code> tag type.
Also defines several preprocessor symbols, as described below.</para>
<macro name="BOOST_VARIANT_LIMIT_TYPES">
<purpose>
<simpara>Expands to the length of the
template parameter list for
<code><classname>variant</classname></code>.</simpara>
</purpose>
<description>
<para><emphasis role="bold">Note</emphasis>: Conforming
implementations of <code>variant</code> must allow at least ten
template arguments. That is, BOOST_VARIANT_LIMIT_TYPES must be greater
or equal to <code>10</code>.</para>
</description>
</macro>
<macro name="BOOST_VARIANT_ENUM_PARAMS" kind="functionlike">
<macro-parameter name="param"/>
@@ -34,7 +28,19 @@
</purpose>
<description>
<para>Expands to a comma-separated sequence of length
<para> Expands to variadic template list in the following manner:
<code><programlisting>
BOOST_VARIANT_ENUM_PARAMS(T) => T0, TN...
BOOST_VARIANT_ENUM_PARAMS(class T) => class T0, class... TN
BOOST_VARIANT_ENUM_PARAMS(class Something) => class Something0, class... SomethingN
BOOST_VARIANT_ENUM_PARAMS(typename Something) => typename Something0, typename... SomethingN
BOOST_VARIANT_ENUM_PARAMS(Something) => Something0, SomethingN...
BOOST_VARIANT_ENUM_PARAMS(Something) => Something0, SomethingN...
</programlisting></code>
</para>
<para>
Otherwise expands to a comma-separated sequence of length
<code><macroname>BOOST_VARIANT_LIMIT_TYPES</macroname></code>, where
each element in the sequence consists of the concatenation of
<emphasis>param</emphasis> with its zero-based index into the
@@ -59,7 +65,19 @@
</purpose>
<description>
<para>Expands to a comma-separated sequence of length
<para> Expands to variadic template list in the following manner:
<code><programlisting>
BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T) => TN...
BOOST_VARIANT_ENUM_SHIFTED_PARAMS(class T) => class... TN
BOOST_VARIANT_ENUM_SHIFTED_PARAMS(class Something) => class... SomethingN
BOOST_VARIANT_ENUM_SHIFTED_PARAMS(typename Something) => typename... SomethingN
BOOST_VARIANT_ENUM_SHIFTED_PARAMS(Something) => SomethingN...
BOOST_VARIANT_ENUM_SHIFTED_PARAMS(Something) => SomethingN...
</programlisting></code>
</para>
<para>
Otherwise expands to a comma-separated sequence of length
<code><macroname>BOOST_VARIANT_LIMIT_TYPES</macroname> - 1</code>,
where each element in the sequence consists of the concatenation of
<emphasis>param</emphasis> with its one-based index into the sequence.
@@ -73,31 +91,11 @@
</description>
</macro>
<macro name="BOOST_VARIANT_NO_REFERENCE_SUPPORT">
<macro name="BOOST_VARIANT_DO_NOT_SPECIALIZE_STD_HASH">
<purpose>
<simpara>Indicates <code><classname>variant</classname></code> does not
support references as bounded types.</simpara>
<simpara>Define this macro if you do not wish to have a <code><classname>std::hash</classname></code> specialization for
<code><classname>boost::variant</classname></code>.</simpara>
</purpose>
<description>
<para>Defined only if <code><classname>variant</classname></code> does
not support references as bounded types.</para>
</description>
</macro>
<macro name="BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT">
<purpose>
<simpara>Indicates absence of support for specifying the bounded types
of a <code><classname>variant</classname></code> by the elements of a
type sequence.</simpara>
</purpose>
<description>
<para>Defined only if
<code><classname>make_variant_over</classname></code> and
<code><classname>make_recursive_variant_over</classname></code>
are not supported for some reason on the target compiler.</para>
</description>
</macro>
<macro name="BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT">
@@ -121,4 +119,4 @@
full lambda support either.)</para>
</description>
</macro>
</header>
</header>
+7 -1
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<header name="boost/variant/visitor_ptr.hpp">
<namespace name="boost">
@@ -105,4 +111,4 @@
</function>
</namespace>
</header>
</header>
+9 -14
View File
@@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Copyright 2013-2026 Antony Polukhin.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<section id="variant.tutorial.advanced">
<title>Advanced Topics</title>
@@ -83,13 +90,6 @@ typedef <classname>mpl::push_front</classname>&lt; types_initial, int &gt;::type
</para>
<para><emphasis role="bold">Portability</emphasis>: Unfortunately, due to
standard conformance issues in several compilers,
<code>make_variant_over</code> is not universally available. On these
compilers the library indicates its lack of support for the syntax via the
definition of the preprocessor symbol
<code><macroname>BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT</macroname></code>.</para>
</section>
<section id="variant.tutorial.recursive">
@@ -390,21 +390,16 @@ struct if_visitor: public <classname>boost::static_visitor</classname>&lt;arithm
arguments by means of <code>apply_visitor</code>:
<programlisting>
bool_like_t v0(1), v1(true), v2(1.0);
bool_like_t v0(true), v1(1), v2(2.0);
assert(
<functionname>boost::apply_visitor</functionname>(if_visitor(), v0, v1, v2)
==
arithmetics_t(true)
arithmetics_t(1)
);
</programlisting>
</para>
<para>Finally, we must note that multi visitation does not support
&quot;delayed&quot; form of
<code><functionname>apply_visitor</functionname></code>.
</para>
</section>
+6
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<section id="variant.tutorial.basic">
<title>Basic Usage</title>
+6
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<section xmlns:xi="http://www.w3.org/2001/XInclude" id="variant.tutorial">
<title>Tutorial</title>
+10
View File
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<!--
Copyright 2003, Eric Friedman, Itay Maman.
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-->
<library name="Variant" dirname="variant"
xmlns:xi="http://www.w3.org/2001/XInclude" id="variant">
<libraryinfo>
@@ -20,6 +26,10 @@
<holder>Itay Maman</holder>
</copyright>
<copyright>
<year>2014-2026</year>
<holder>Antony Polukhin</holder>
</copyright>
<legalnotice>
<para>Distributed under the Boost Software License, Version 1.0.
(See accompanying file <filename>LICENSE_1_0.txt</filename> or copy at
+7 -7
View File
@@ -14,14 +14,14 @@
#define BOOST_VARIANT_HPP
// variant "main"
#include "boost/variant/variant.hpp"
#include "boost/variant/recursive_variant.hpp"
#include "boost/variant/recursive_wrapper.hpp"
#include <boost/variant/variant.hpp>
#include <boost/variant/recursive_variant.hpp>
#include <boost/variant/recursive_wrapper.hpp>
// common applications
#include "boost/variant/get.hpp"
#include "boost/variant/apply_visitor.hpp"
#include "boost/variant/static_visitor.hpp"
#include "boost/variant/visitor_ptr.hpp"
#include <boost/variant/get.hpp>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/static_visitor.hpp>
#include <boost/variant/visitor_ptr.hpp>
#endif // BOOST_VARIANT_HPP
+3 -3
View File
@@ -13,8 +13,8 @@
#ifndef BOOST_VARIANT_APPLY_VISITOR_HPP
#define BOOST_VARIANT_APPLY_VISITOR_HPP
#include "boost/variant/detail/apply_visitor_unary.hpp"
#include "boost/variant/detail/apply_visitor_binary.hpp"
#include "boost/variant/detail/apply_visitor_delayed.hpp"
#include <boost/variant/detail/apply_visitor_unary.hpp>
#include <boost/variant/detail/apply_visitor_binary.hpp>
#include <boost/variant/detail/apply_visitor_delayed.hpp>
#endif // BOOST_VARIANT_APPLY_VISITOR_HPP
+4 -2
View File
@@ -13,6 +13,8 @@
#ifndef BOOST_VARIANT_BAD_VISIT_HPP
#define BOOST_VARIANT_BAD_VISIT_HPP
#include <boost/config.hpp>
#include <exception>
namespace boost {
@@ -23,12 +25,12 @@ namespace boost {
// Exception thrown when a visitation attempt via apply_visitor fails due
// to invalid visited subtype or contents.
//
struct bad_visit
struct BOOST_SYMBOL_VISIBLE bad_visit
: std::exception
{
public: // std::exception interface
virtual const char * what() const throw()
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
{
return "boost::bad_visit: "
"failed visitation using boost::apply_visitor";
@@ -3,8 +3,8 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2002-2003
// Eric Friedman
// Copyright (c) 2002-2003 Eric Friedman
// Copyright (c) 2014-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -13,18 +13,19 @@
#ifndef BOOST_VARIANT_DETAIL_APPLY_VISITOR_BINARY_HPP
#define BOOST_VARIANT_DETAIL_APPLY_VISITOR_BINARY_HPP
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
#include "boost/variant/detail/generic_result_type.hpp"
#include <boost/config.hpp>
#include "boost/variant/detail/apply_visitor_unary.hpp"
#include <boost/variant/detail/apply_visitor_unary.hpp>
#if BOOST_WORKAROUND(__EDG__, BOOST_TESTED_AT(302))
#include "boost/utility/enable_if.hpp"
#include "boost/mpl/not.hpp"
#include "boost/type_traits/is_const.hpp"
#if !defined(BOOST_NO_CXX14_DECLTYPE_AUTO) && !defined(BOOST_NO_CXX11_DECLTYPE_N3276)
# include <boost/variant/detail/has_result_type.hpp>
#endif
#include <boost/core/enable_if.hpp>
#include <boost/type_traits/is_lvalue_reference.hpp>
#include <boost/type_traits/is_same.hpp>
#include <utility>
namespace boost {
//////////////////////////////////////////////////////////////////////////
@@ -37,7 +38,7 @@ namespace boost {
namespace detail { namespace variant {
template <typename Visitor, typename Value1>
template <typename Visitor, typename Value1, bool MoveSemantics>
class apply_visitor_binary_invoke
{
public: // visitor typedefs
@@ -52,7 +53,7 @@ private: // representation
public: // structors
apply_visitor_binary_invoke(Visitor& visitor, Value1& value1)
apply_visitor_binary_invoke(Visitor& visitor, Value1& value1) BOOST_NOEXCEPT
: visitor_(visitor)
, value1_(value1)
{
@@ -61,18 +62,24 @@ public: // structors
public: // visitor interfaces
template <typename Value2>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
operator()(Value2& value2)
typename enable_if_c<MoveSemantics && is_same<Value2, Value2>::value, result_type>::type
operator()(Value2&& value2)
{
return visitor_(value1_, value2);
return visitor_(std::move(value1_), std::forward<Value2>(value2));
}
template <typename Value2>
typename disable_if_c<MoveSemantics && is_same<Value2, Value2>::value, result_type>::type
operator()(Value2&& value2)
{
return visitor_(value1_, std::forward<Value2>(value2));
}
private:
apply_visitor_binary_invoke& operator=(const apply_visitor_binary_invoke&);
};
template <typename Visitor, typename Visitable2>
template <typename Visitor, typename Visitable2, bool MoveSemantics>
class apply_visitor_binary_unwrap
{
public: // visitor typedefs
@@ -87,7 +94,7 @@ private: // representation
public: // structors
apply_visitor_binary_unwrap(Visitor& visitor, Visitable2& visitable2)
apply_visitor_binary_unwrap(Visitor& visitor, Visitable2& visitable2) BOOST_NOEXCEPT
: visitor_(visitor)
, visitable2_(visitable2)
{
@@ -96,12 +103,26 @@ public: // structors
public: // visitor interfaces
template <typename Value1>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
operator()(Value1& value1)
typename enable_if_c<MoveSemantics && is_same<Value1, Value1>::value, result_type>::type
operator()(Value1&& value1)
{
apply_visitor_binary_invoke<
Visitor
, Value1
, ! ::boost::is_lvalue_reference<Value1>::value
> invoker(visitor_, value1);
return boost::apply_visitor(invoker, std::move(visitable2_));
}
template <typename Value1>
typename disable_if_c<MoveSemantics && is_same<Value1, Value1>::value, result_type>::type
operator()(Value1&& value1)
{
apply_visitor_binary_invoke<
Visitor
, Value1
, ! ::boost::is_lvalue_reference<Value1>::value
> invoker(visitor_, value1);
return boost::apply_visitor(invoker, visitable2_);
@@ -118,64 +139,152 @@ private:
// nonconst-visitor version:
//
#if !BOOST_WORKAROUND(__EDG__, BOOST_TESTED_AT(302))
# define BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(V) \
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename V::result_type) \
/**/
#else // EDG-based compilers
# define BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(V) \
typename enable_if< \
mpl::not_< is_const< V > > \
, BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename V::result_type) \
>::type \
/**/
#endif // EDG-based compilers workaround
template <typename Visitor, typename Visitable1, typename Visitable2>
inline
BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(Visitor)
apply_visitor(
Visitor& visitor
, Visitable1& visitable1, Visitable2& visitable2
)
inline typename Visitor::result_type
apply_visitor( Visitor& visitor, Visitable1&& visitable1, Visitable2&& visitable2)
{
::boost::detail::variant::apply_visitor_binary_unwrap<
Visitor, Visitable2
Visitor, Visitable2, ! ::boost::is_lvalue_reference<Visitable2>::value
> unwrapper(visitor, visitable2);
return boost::apply_visitor(unwrapper, visitable1);
return boost::apply_visitor(unwrapper, std::forward<Visitable1>(visitable1));
}
#undef BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE
//
// const-visitor version:
//
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
template <typename Visitor, typename Visitable1, typename Visitable2>
inline
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(
typename Visitor::result_type
)
apply_visitor(
const Visitor& visitor
, Visitable1& visitable1, Visitable2& visitable2
)
inline typename Visitor::result_type
apply_visitor( const Visitor& visitor , Visitable1&& visitable1 , Visitable2&& visitable2)
{
::boost::detail::variant::apply_visitor_binary_unwrap<
const Visitor, Visitable2
const Visitor, Visitable2, ! ::boost::is_lvalue_reference<Visitable2>::value
> unwrapper(visitor, visitable2);
return boost::apply_visitor(unwrapper, visitable1);
return boost::apply_visitor(unwrapper, std::forward<Visitable1>(visitable1));
}
#endif // MSVC7 and below exclusion
#if !defined(BOOST_NO_CXX14_DECLTYPE_AUTO) && !defined(BOOST_NO_CXX11_DECLTYPE_N3276)
//////////////////////////////////////////////////////////////////////////
// function template apply_visitor(visitor, visitable1, visitable2)
//
// C++14 part.
//
namespace detail { namespace variant {
template <typename Visitor, typename Value1, bool MoveSemantics>
class apply_visitor_binary_invoke_cpp14
{
Visitor& visitor_;
Value1& value1_;
public: // structors
apply_visitor_binary_invoke_cpp14(Visitor& visitor, Value1& value1) BOOST_NOEXCEPT
: visitor_(visitor)
, value1_(value1)
{
}
public: // visitor interfaces
template <typename Value2>
decltype(auto) operator()(Value2&& value2, typename enable_if_c<MoveSemantics && is_same<Value2, Value2>::value, bool>::type = true)
{
return visitor_(std::move(value1_), std::forward<Value2>(value2));
}
template <typename Value2>
decltype(auto) operator()(Value2&& value2, typename disable_if_c<MoveSemantics && is_same<Value2, Value2>::value, bool>::type = true)
{
return visitor_(value1_, std::forward<Value2>(value2));
}
private:
apply_visitor_binary_invoke_cpp14& operator=(const apply_visitor_binary_invoke_cpp14&);
};
template <typename Visitor, typename Visitable2, bool MoveSemantics>
class apply_visitor_binary_unwrap_cpp14
{
Visitor& visitor_;
Visitable2& visitable2_;
public: // structors
apply_visitor_binary_unwrap_cpp14(Visitor& visitor, Visitable2& visitable2) BOOST_NOEXCEPT
: visitor_(visitor)
, visitable2_(visitable2)
{
}
public: // visitor interfaces
template <typename Value1>
decltype(auto) operator()(Value1&& value1, typename enable_if_c<MoveSemantics && is_same<Value1, Value1>::value, bool>::type = true)
{
apply_visitor_binary_invoke_cpp14<
Visitor
, Value1
, ! ::boost::is_lvalue_reference<Value1>::value
> invoker(visitor_, value1);
return boost::apply_visitor(invoker, std::move(visitable2_));
}
template <typename Value1>
decltype(auto) operator()(Value1&& value1, typename disable_if_c<MoveSemantics && is_same<Value1, Value1>::value, bool>::type = true)
{
apply_visitor_binary_invoke_cpp14<
Visitor
, Value1
, ! ::boost::is_lvalue_reference<Value1>::value
> invoker(visitor_, value1);
return boost::apply_visitor(invoker, visitable2_);
}
private:
apply_visitor_binary_unwrap_cpp14& operator=(const apply_visitor_binary_unwrap_cpp14&);
};
}} // namespace detail::variant
template <typename Visitor, typename Visitable1, typename Visitable2>
inline decltype(auto) apply_visitor(Visitor& visitor, Visitable1&& visitable1, Visitable2&& visitable2,
typename boost::disable_if<
boost::detail::variant::has_result_type<Visitor>,
bool
>::type = true)
{
::boost::detail::variant::apply_visitor_binary_unwrap_cpp14<
Visitor, Visitable2, ! ::boost::is_lvalue_reference<Visitable2>::value
> unwrapper(visitor, visitable2);
return boost::apply_visitor(unwrapper, std::forward<Visitable1>(visitable1));
}
template <typename Visitor, typename Visitable1, typename Visitable2>
inline decltype(auto) apply_visitor(const Visitor& visitor, Visitable1&& visitable1, Visitable2&& visitable2,
typename boost::disable_if<
boost::detail::variant::has_result_type<Visitor>,
bool
>::type = true)
{
::boost::detail::variant::apply_visitor_binary_unwrap_cpp14<
const Visitor, Visitable2, ! ::boost::is_lvalue_reference<Visitable2>::value
> unwrapper(visitor, visitable2);
return boost::apply_visitor(unwrapper, std::forward<Visitable1>(visitable1));
}
#endif // !defined(BOOST_NO_CXX14_DECLTYPE_AUTO) && !defined(BOOST_NO_CXX11_DECLTYPE_N3276)
} // namespace boost
@@ -13,10 +13,13 @@
#ifndef BOOST_VARIANT_DETAIL_APPLY_VISITOR_DELAYED_HPP
#define BOOST_VARIANT_DETAIL_APPLY_VISITOR_DELAYED_HPP
#include "boost/variant/detail/generic_result_type.hpp"
#include <boost/variant/detail/apply_visitor_unary.hpp>
#include <boost/variant/detail/apply_visitor_binary.hpp>
#include <boost/variant/variant_fwd.hpp>
#include "boost/variant/detail/apply_visitor_unary.hpp"
#include "boost/variant/detail/apply_visitor_binary.hpp"
#include <boost/variant/detail/has_result_type.hpp>
#include <boost/core/enable_if.hpp>
namespace boost {
@@ -49,27 +52,16 @@ private: // representation
public: // structors
explicit apply_visitor_delayed_t(Visitor& visitor)
explicit apply_visitor_delayed_t(Visitor& visitor) BOOST_NOEXCEPT
: visitor_(visitor)
{
}
public: // unary visitor interface
template <typename Visitable>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
operator()(Visitable& visitable) const
public: // N-ary visitor interface
template <typename... Visitables>
result_type operator()(Visitables&... visitables) const
{
return apply_visitor(visitor_, visitable);
}
public: // binary visitor interface
template <typename Visitable1, typename Visitable2>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
operator()(Visitable1& visitable1, Visitable2& visitable2) const
{
return apply_visitor(visitor_, visitable1, visitable2);
return apply_visitor(visitor_, visitables...);
}
private:
@@ -78,11 +70,53 @@ private:
};
template <typename Visitor>
inline apply_visitor_delayed_t<Visitor> apply_visitor(Visitor& visitor)
inline typename boost::enable_if<
boost::detail::variant::has_result_type<Visitor>,
apply_visitor_delayed_t<Visitor>
>::type apply_visitor(Visitor& visitor)
{
return apply_visitor_delayed_t<Visitor>(visitor);
}
#if !defined(BOOST_NO_CXX14_DECLTYPE_AUTO)
template <typename Visitor>
class apply_visitor_delayed_cpp14_t
{
private: // representation
Visitor& visitor_;
public: // structors
explicit apply_visitor_delayed_cpp14_t(Visitor& visitor) BOOST_NOEXCEPT
: visitor_(visitor)
{
}
public: // N-ary visitor interface
template <typename... Visitables>
decltype(auto) operator()(Visitables&... visitables) const
{
return apply_visitor(visitor_, visitables...);
}
private:
apply_visitor_delayed_cpp14_t& operator=(const apply_visitor_delayed_cpp14_t&);
};
template <typename Visitor>
inline typename boost::disable_if<
boost::detail::variant::has_result_type<Visitor>,
apply_visitor_delayed_cpp14_t<Visitor>
>::type apply_visitor(Visitor& visitor)
{
return apply_visitor_delayed_cpp14_t<Visitor>(visitor);
}
#endif // !defined(BOOST_NO_CXX14_DECLTYPE_AUTO)
} // namespace boost
#endif // BOOST_VARIANT_DETAIL_APPLY_VISITOR_DELAYED_HPP
@@ -3,8 +3,8 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2002-2003
// Eric Friedman
// Copyright (c) 2002-2003 Eric Friedman
// Copyright (c) 2014-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -13,14 +13,19 @@
#ifndef BOOST_VARIANT_DETAIL_APPLY_VISITOR_UNARY_HPP
#define BOOST_VARIANT_DETAIL_APPLY_VISITOR_UNARY_HPP
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
#include "boost/variant/detail/generic_result_type.hpp"
#include <boost/config.hpp>
#include <utility>
#if BOOST_WORKAROUND(__EDG__, BOOST_TESTED_AT(302))
#include "boost/utility/enable_if.hpp"
#include "boost/mpl/not.hpp"
#include "boost/type_traits/is_const.hpp"
#if !defined(BOOST_NO_CXX14_DECLTYPE_AUTO) && !defined(BOOST_NO_CXX11_DECLTYPE_N3276)
# include <boost/mpl/distance.hpp>
# include <boost/mpl/advance.hpp>
# include <boost/mpl/deref.hpp>
# include <boost/mpl/size.hpp>
# include <boost/utility/declval.hpp>
# include <boost/core/enable_if.hpp>
# include <boost/type_traits/copy_cv_ref.hpp>
# include <boost/type_traits/remove_reference.hpp>
# include <boost/variant/detail/has_result_type.hpp>
#endif
namespace boost {
@@ -35,48 +40,87 @@ namespace boost {
// nonconst-visitor version:
//
#if !BOOST_WORKAROUND(__EDG__, BOOST_TESTED_AT(302))
# define BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(V) \
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename V::result_type) \
/**/
#else // EDG-based compilers
# define BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(V) \
typename enable_if< \
mpl::not_< is_const< V > > \
, BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename V::result_type) \
>::type \
/**/
#endif // EDG-based compilers workaround
template <typename Visitor, typename Visitable>
inline
BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(Visitor)
apply_visitor(Visitor& visitor, Visitable& visitable)
inline typename Visitor::result_type
apply_visitor(Visitor& visitor, Visitable&& visitable)
{
return visitable.apply_visitor(visitor);
return std::forward<Visitable>(visitable).apply_visitor(visitor);
}
#undef BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE
//
// const-visitor version:
//
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
template <typename Visitor, typename Visitable>
inline
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
apply_visitor(const Visitor& visitor, Visitable& visitable)
inline typename Visitor::result_type
apply_visitor(const Visitor& visitor, Visitable&& visitable)
{
return visitable.apply_visitor(visitor);
return std::forward<Visitable>(visitable).apply_visitor(visitor);
}
#endif // MSVC7 and below exclusion
#if !defined(BOOST_NO_CXX14_DECLTYPE_AUTO) && !defined(BOOST_NO_CXX11_DECLTYPE_N3276)
#define BOOST_VARIANT_HAS_DECLTYPE_APPLY_VISITOR_RETURN_TYPE
// C++14
namespace detail { namespace variant {
// This class serves only metaprogramming purposes. none of its methods must be called at runtime!
template <class Visitor, class Variant>
struct result_multideduce1 {
typedef typename remove_reference<Variant>::type::types types;
typedef typename boost::mpl::begin<types>::type begin_it;
typedef typename boost::mpl::advance<
begin_it, boost::mpl::int_<boost::mpl::size<types>::type::value - 1>
>::type last_it;
template <class It, class Dummy = void> // avoid explicit specialization in class scope
struct deduce_impl {
typedef typename boost::mpl::next<It>::type next_t;
typedef typename boost::mpl::deref<It>::type value_t;
typedef decltype(true ? boost::declval< Visitor& >()( boost::declval< copy_cv_ref_t< value_t, Variant > >() )
: boost::declval< typename deduce_impl<next_t>::type >()) type;
};
template <class Dummy>
struct deduce_impl<last_it, Dummy> {
typedef typename boost::mpl::deref<last_it>::type value_t;
typedef decltype(boost::declval< Visitor& >()( boost::declval< copy_cv_ref_t< value_t, Variant > >() )) type;
};
typedef typename deduce_impl<begin_it>::type type;
};
template <class Visitor, class Variant>
struct result_wrapper1
{
typedef typename result_multideduce1<Visitor, Variant>::type result_type;
Visitor&& visitor_;
explicit result_wrapper1(Visitor&& visitor) BOOST_NOEXCEPT
: visitor_(std::forward<Visitor>(visitor))
{}
template <class T>
result_type operator()(T&& val) const {
return visitor_(std::forward<T>(val));
}
};
}} // namespace detail::variant
template <typename Visitor, typename Visitable>
inline decltype(auto) apply_visitor(Visitor&& visitor, Visitable&& visitable,
typename boost::disable_if<
boost::detail::variant::has_result_type<Visitor>,
bool
>::type = true)
{
boost::detail::variant::result_wrapper1<Visitor, Visitable> cpp14_vis(std::forward<Visitor>(visitor));
return std::forward<Visitable>(visitable).apply_visitor(cpp14_vis);
}
#endif // !defined(BOOST_NO_CXX14_DECLTYPE_AUTO) && !defined(BOOST_NO_CXX11_DECLTYPE_N3276)
} // namespace boost
@@ -13,8 +13,8 @@
#ifndef BOOST_VARIANT_DETAIL_BACKUP_HOLDER_HPP
#define BOOST_VARIANT_DETAIL_BACKUP_HOLDER_HPP
#include "boost/config.hpp"
#include "boost/assert.hpp"
#include <boost/config.hpp>
#include <boost/assert.hpp>
namespace boost {
namespace detail { namespace variant {
@@ -28,7 +28,7 @@ private: // representation
public: // structors
~backup_holder()
~backup_holder() BOOST_NOEXCEPT
{
delete backup_;
}
@@ -63,12 +63,12 @@ public: // modifiers
public: // queries
T& get()
T& get() BOOST_NOEXCEPT
{
return *backup_;
}
const T& get() const
const T& get() const BOOST_NOEXCEPT
{
return *backup_;
}
@@ -1,30 +0,0 @@
//-----------------------------------------------------------------------------
// boost/variant/detail/bool_trait_def.hpp header file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2003
// Eric Friedman
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Needed until move-related traits incorporated into type_traits library.
// no include guards, the header is intended for multiple inclusion!
// should be the last #include
#include "boost/type_traits/detail/bool_trait_def.hpp"
#define BOOST_VARIANT_TT_AUX_BOOL_TRAIT_DEF1(trait,T,C) \
template< typename T > struct trait \
BOOST_TT_AUX_BOOL_C_BASE(C) \
{ \
BOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(C) \
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,trait,(T)) \
}; \
/**/
#define BOOST_VARIANT_TT_AUX_TRAIT_SUFFIX(arity, name) \
BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(arity, name) \
/**/
@@ -1,21 +0,0 @@
//-----------------------------------------------------------------------------
// boost/variant/detail/bool_trait_undef.hpp header file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2003
// Eric Friedman
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Needed until move-related traits incorporated into type_traits library.
// no include guards, the header is intended for multiple inclusion!
// should be the last #include
#include "boost/type_traits/detail/bool_trait_undef.hpp"
#undef BOOST_VARIANT_TT_AUX_BOOL_TRAIT_DEF1
#undef BOOST_VARIANT_TT_AUX_TRAIT_SUFFIX
@@ -13,7 +13,7 @@
#ifndef BOOST_VARIANT_DETAIL_CAST_STORAGE_HPP
#define BOOST_VARIANT_DETAIL_CAST_STORAGE_HPP
#include "boost/config.hpp"
#include <boost/config.hpp>
namespace boost {
namespace detail { namespace variant {
@@ -25,19 +25,13 @@ namespace detail { namespace variant {
//
template <typename T>
inline T& cast_storage(
void* storage
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)
)
inline T& cast_storage(void* storage)
{
return *static_cast<T*>(storage);
}
template <typename T>
inline const T& cast_storage(
const void* storage
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)
)
inline const T& cast_storage(const void* storage)
{
return *static_cast<const T*>(storage);
}
+4 -23
View File
@@ -3,8 +3,8 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2003
// Eric Friedman
// Copyright (c) 2003 Eric Friedman
// Copyright (c) 2016-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -13,26 +13,7 @@
#ifndef BOOST_VARIANT_DETAIL_CONFIG_HPP
#define BOOST_VARIANT_DETAIL_CONFIG_HPP
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
///////////////////////////////////////////////////////////////////////////////
// macro BOOST_VARIANT_AUX_BROKEN_CONSTRUCTOR_TEMPLATE_ORDERING
//
#if BOOST_WORKAROUND(__MWERKS__, <= 0x3201) \
|| BOOST_WORKAROUND(BOOST_INTEL, <= 700) \
|| BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
&& !defined(BOOST_VARIANT_AUX_BROKEN_CONSTRUCTOR_TEMPLATE_ORDERING)
# define BOOST_VARIANT_AUX_BROKEN_CONSTRUCTOR_TEMPLATE_ORDERING
#endif
///////////////////////////////////////////////////////////////////////////////
// macro BOOST_VARIANT_AUX_HAS_CONSTRUCTOR_TEMPLATE_ORDERING_SFINAE_WKND
//
#if !defined(BOOST_NO_SFINAE) \
&& !BOOST_WORKAROUND(BOOST_INTEL, <= 700) \
&& !defined(BOOST_VARIANT_AUX_HAS_CONSTRUCTOR_TEMPLATE_ORDERING_SFINAE_WKND)
# define BOOST_VARIANT_AUX_HAS_CONSTRUCTOR_TEMPLATE_ORDERING_SFINAE_WKND
#endif
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#endif // BOOST_VARIANT_DETAIL_CONFIG_HPP
@@ -0,0 +1,63 @@
//-----------------------------------------------------------------------------
// boost variant/detail/element_index.hpp header file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2014-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_VARIANT_DETAIL_ELEMENT_INDEX_HPP
#define BOOST_VARIANT_DETAIL_ELEMENT_INDEX_HPP
#include <boost/config.hpp>
#include <boost/variant/recursive_wrapper_fwd.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/mpl/find_if.hpp>
namespace boost { namespace detail { namespace variant {
template <class VariantElement, class T>
struct variant_element_functor :
boost::mpl::or_<
boost::is_same<VariantElement, T>,
boost::is_same<VariantElement, boost::recursive_wrapper<T> >,
boost::is_same<VariantElement, T& >
>
{};
template <class Types, class T>
struct element_iterator_impl :
boost::mpl::find_if<
Types,
boost::mpl::or_<
variant_element_functor<boost::mpl::_1, T>,
variant_element_functor<boost::mpl::_1, typename boost::remove_cv<T>::type >
>
>
{};
template <class Variant, class T>
struct element_iterator :
element_iterator_impl< typename Variant::types, typename boost::remove_reference<T>::type >
{};
template <class Variant, class T>
struct holds_element :
boost::mpl::not_<
boost::is_same<
typename boost::mpl::end<typename Variant::types>::type,
typename element_iterator<Variant, T>::type
>
>
{};
}}} // namespace boost::detail::variant
#endif // BOOST_VARIANT_DETAIL_ELEMENT_INDEX_HPP
@@ -13,72 +13,39 @@
#ifndef BOOST_VARIANT_DETAIL_ENABLE_RECURSIVE_HPP
#define BOOST_VARIANT_DETAIL_ENABLE_RECURSIVE_HPP
#include "boost/variant/detail/enable_recursive_fwd.hpp"
#include "boost/variant/variant_fwd.hpp"
#include <boost/variant/detail/enable_recursive_fwd.hpp>
#include <boost/variant/variant_fwd.hpp>
#if !defined(BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT)
# include "boost/mpl/apply.hpp"
# include "boost/mpl/eval_if.hpp"
# include "boost/mpl/lambda.hpp"
# include <boost/mpl/apply.hpp>
# include <boost/mpl/eval_if.hpp>
# include <boost/mpl/lambda.hpp>
#endif
#include "boost/variant/detail/substitute.hpp"
#include "boost/mpl/aux_/config/ctps.hpp"
#include "boost/mpl/bool_fwd.hpp"
#include "boost/mpl/if.hpp"
#include "boost/mpl/or.hpp"
#include "boost/type_traits/is_pointer.hpp"
#include "boost/type_traits/is_reference.hpp"
#include "boost/type_traits/is_same.hpp"
#include <boost/variant/detail/substitute.hpp>
#include <boost/mpl/aux_/config/ctps.hpp>
#include <boost/mpl/bool_fwd.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/or.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/is_same.hpp>
#include "boost/variant/recursive_wrapper.hpp"
#include <boost/variant/recursive_wrapper.hpp>
namespace boost {
namespace detail { namespace variant {
#if !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
# define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(T,Dest,Source) \
substitute< T , Dest , Source > \
/**/
#else // defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
///////////////////////////////////////////////////////////////////////////////
// (detail) class template rebind1
//
// Limited workaround in case 'substitute' metafunction unavailable.
//
template <typename T, typename U1>
struct rebind1
{
private:
typedef typename mpl::lambda<
mpl::identity<T>
>::type le_;
public:
typedef typename mpl::eval_if<
is_same< le_, mpl::identity<T> >
, le_ // identity<T>
, mpl::apply1<le_, U1>
>::type type;
};
# define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(T,Dest,Source) \
rebind1< T , Dest > \
/**/
#endif // !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
///////////////////////////////////////////////////////////////////////////////
// (detail) metafunction enable_recursive
//
// See boost/variant/detail/enable_recursive_fwd.hpp for more information.
//
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename T, typename RecursiveVariant, typename NoWrapper>
struct enable_recursive
@@ -112,34 +79,6 @@ public: // metafunction result
};
#else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename T, typename RecursiveVariant, typename NoWrapper>
struct enable_recursive
{
private: // helpers, for metafunction result (below)
typedef typename BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(
T, RecursiveVariant, ::boost::recursive_variant_
)::type t_;
public: // metafunction result
// [Wrap with recursive_wrapper only if rebind really changed something:]
typedef typename mpl::if_<
mpl::or_<
NoWrapper
, is_same< t_,T >
, is_reference<t_>
, is_pointer<t_>
>
, t_
, boost::recursive_wrapper<t_>
>::type type;
};
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
///////////////////////////////////////////////////////////////////////////////
// (detail) metafunction class quoted_enable_recursive
@@ -13,15 +13,11 @@
#ifndef BOOST_VARIANT_DETAIL_ENABLE_RECURSIVE_FWD_HPP
#define BOOST_VARIANT_DETAIL_ENABLE_RECURSIVE_FWD_HPP
#include "boost/mpl/aux_/config/ctps.hpp"
#include <boost/mpl/aux_/config/ctps.hpp>
#include "boost/mpl/bool_fwd.hpp"
#include <boost/mpl/bool_fwd.hpp>
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
# include "boost/mpl/bool.hpp"
#else
# include "boost/type_traits/is_base_and_derived.hpp"
#endif
# include <boost/mpl/bool.hpp>
namespace boost {
namespace detail { namespace variant {
@@ -32,7 +28,6 @@ namespace detail { namespace variant {
// Signifies that the variant should perform recursive substituion.
//
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename T>
struct recursive_flag
@@ -40,20 +35,6 @@ struct recursive_flag
typedef T type;
};
#else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
struct recursive_flag_tag
{
};
template <typename T>
struct recursive_flag
: recursive_flag_tag
{
typedef T type;
};
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
///////////////////////////////////////////////////////////////////////////////
// (detail) metafunction is_recursive_flag
@@ -61,7 +42,6 @@ struct recursive_flag
// Signifies that the variant should perform recursive substituion.
//
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename T>
struct is_recursive_flag
@@ -75,15 +55,6 @@ struct is_recursive_flag< recursive_flag<T> >
{
};
#else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename T>
struct is_recursive_flag
: is_base_and_derived< recursive_flag_tag,T >
{
};
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
///////////////////////////////////////////////////////////////////////////////
// (detail) metafunction enable_recursive
+18 -70
View File
@@ -3,8 +3,8 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2003
// Eric Friedman
// Copyright (c) 2003 Eric Friedman
// Copyright (c) 2015-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -13,16 +13,16 @@
#ifndef BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP
#define BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP
#include "boost/config.hpp"
#include "boost/variant/detail/generic_result_type.hpp"
#include "boost/assert.hpp"
#include <boost/config.hpp>
#include <boost/assert.hpp>
#if !defined(BOOST_MSVC) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
# include "boost/type_traits/remove_reference.hpp"
#ifdef BOOST_MSVC
# pragma warning( push )
# pragma warning( disable : 4702 ) // unreachable code
#endif
namespace boost {
namespace detail { namespace variant {
namespace boost { namespace detail { namespace variant {
///////////////////////////////////////////////////////////////////////////////
// (detail) function template forced_return
@@ -30,75 +30,23 @@ namespace detail { namespace variant {
// Logical error to permit invocation at runtime, but (artificially) satisfies
// compile-time requirement of returning a result value.
//
#if !defined(BOOST_MSVC) \
&& !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
&& !defined(BOOST_NO_VOID_RETURNS)
// "standard" implementation:
template <typename T>
inline T forced_return( BOOST_EXPLICIT_TEMPLATE_TYPE(T) )
BOOST_NORETURN inline T
forced_return()
{
// logical error: should never be here! (see above)
BOOST_ASSERT(false);
typedef typename boost::remove_reference<T>::type basic_type;
basic_type* dummy = 0;
return *static_cast< basic_type* >(dummy);
T (*dummy)() = 0;
(void)dummy;
BOOST_UNREACHABLE_RETURN(dummy());
}
template <>
inline void forced_return<void>( BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(void) )
{
// logical error: should never be here! (see above)
BOOST_ASSERT(false);
}
}}} // namespace boost::detail::variant
#elif !defined(BOOST_MSVC)
// workaround implementation
//
// TODO: Determine the most efficient way to handle this -- as below? by
// throwing? by recursive call to forced_return itself? etc.
//
template <typename T>
inline
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T)
forced_return( BOOST_EXPLICIT_TEMPLATE_TYPE(T) )
{
// logical error: should never be here! (see above)
BOOST_ASSERT(false);
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T) (*dummy)() = 0;
return dummy();
}
#else // defined(BOOST_MSVC)
// msvc-specific implementation
//
// Leverages __declspec(noreturn) for optimized implementation.
//
__declspec(noreturn)
inline void forced_return_no_return() {};
template <typename T>
inline
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T)
forced_return( BOOST_EXPLICIT_TEMPLATE_TYPE(T) )
{
// logical error: should never be here! (see above)
BOOST_ASSERT(false);
forced_return_no_return();
}
#endif // BOOST_MSVC optimization
}} // namespace detail::variant
} // namespace boost
#ifdef BOOST_MSVC
# pragma warning( pop )
#endif
#endif // BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP
@@ -1,88 +0,0 @@
//-----------------------------------------------------------------------------
// boost variant/detail/generic_result_type.hpp header file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2003
// Eric Friedman
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_VARIANT_DETAIL_GENERIC_RESULT_TYPE_HPP
#define BOOST_VARIANT_DETAIL_GENERIC_RESULT_TYPE_HPP
#include "boost/config.hpp"
//////////////////////////////////////////////////////////////////////////
// (workaround) macro BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE
//
// On compilers with BOOST_NO_VOID_RETURNS, this macro provides a route
// to a single syntax for dealing with template functions that may (but
// not necessarily) return nothing (i.e. void).
//
// BOOST_VARIANT_AUX_RETURN_VOID provided for compilers w/ (erroneous?)
// warnings about non-void functions not returning a value.
//
#if !defined(BOOST_NO_VOID_RETURNS)
#define BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T) \
T \
/**/
#define BOOST_VARIANT_AUX_RETURN_VOID \
/**/
#define BOOST_VARIANT_AUX_RETURN_VOID_TYPE \
void \
/**/
#else // defined(BOOST_NO_VOID_RETURNS)
namespace boost {
namespace detail { namespace variant {
struct fake_return_void
{
fake_return_void()
{
}
template <typename T>
fake_return_void(const T&)
{
}
};
template <typename T>
struct no_void_returns_helper
{
typedef T type;
};
template <>
struct no_void_returns_helper<void>
{
typedef fake_return_void type;
};
}} // namespace detail::variant
} // namespace boost
#define BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T) \
BOOST_DEDUCED_TYPENAME \
::boost::detail::variant::no_void_returns_helper< T >::type \
/**/
#define BOOST_VARIANT_AUX_RETURN_VOID \
return ::boost::detail::variant::fake_return_void() \
/**/
#define BOOST_VARIANT_AUX_RETURN_VOID_TYPE \
::boost::detail::variant::fake_return_void
#endif // BOOST_NO_VOID_RETURNS workaround
#endif // BOOST_VARIANT_DETAIL_GENERIC_RESULT_TYPE_HPP
@@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
// boost variant/detail/has_result_type.hpp header file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2014-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_VARIANT_DETAIL_HAS_RESULT_TYPE_HPP
#define BOOST_VARIANT_DETAIL_HAS_RESULT_TYPE_HPP
#include <boost/config.hpp>
#include <boost/type_traits/remove_reference.hpp>
namespace boost { namespace detail { namespace variant {
template <typename T >
struct has_result_type {
private:
typedef char yes;
typedef struct { char array[2]; } no;
template<typename C> static yes test(typename boost::remove_reference<typename C::result_type>::type*);
template<typename C> static no test(...);
public:
BOOST_STATIC_CONSTANT(bool, value = sizeof(test<T>(0)) == sizeof(yes));
};
}}} // namespace boost::detail::variant
#endif // BOOST_VARIANT_DETAIL_HAS_RESULT_TYPE_HPP
@@ -3,8 +3,7 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2011
// Antony Polukhin
// Copyright (c) 2011-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -14,7 +13,7 @@
#ifndef BOOST_HASH_VARIANT_FUNCTION_HPP
#define BOOST_HASH_VARIANT_FUNCTION_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#if defined(_MSC_VER)
# pragma once
#endif
+13 -143
View File
@@ -15,27 +15,21 @@
#include <new> // for placement new
#include "boost/config.hpp"
#include <boost/config.hpp>
#include "boost/call_traits.hpp"
#include "boost/detail/reference_content.hpp"
#include "boost/variant/recursive_wrapper_fwd.hpp"
#include "boost/variant/detail/move.hpp"
#include <boost/call_traits.hpp>
#include <boost/detail/reference_content.hpp>
#include <boost/variant/recursive_wrapper_fwd.hpp>
#include <boost/variant/detail/move.hpp>
# include <boost/mpl/aux_/value_wknd.hpp>
# include <boost/mpl/int.hpp>
# include <boost/mpl/iter_fold.hpp>
# include <boost/mpl/next.hpp>
# include <boost/mpl/deref.hpp>
# include <boost/mpl/pair.hpp>
# include <boost/mpl/protect.hpp>
#if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
# include "boost/mpl/aux_/value_wknd.hpp"
# include "boost/mpl/int.hpp"
# include "boost/mpl/iter_fold.hpp"
# include "boost/mpl/next.hpp"
# include "boost/mpl/deref.hpp"
# include "boost/mpl/pair.hpp"
# include "boost/mpl/protect.hpp"
#else
# include "boost/variant/variant_fwd.hpp"
# include "boost/preprocessor/cat.hpp"
# include "boost/preprocessor/enum.hpp"
# include "boost/preprocessor/repeat.hpp"
#endif
namespace boost {
namespace detail { namespace variant {
@@ -53,8 +47,6 @@ namespace detail { namespace variant {
// size of the variant's psuedo-variadic template parameter list.
//
#if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
// (detail) quoted metafunction make_initializer_node
//
// Exposes a pair whose first type is a node in the initializer hierarchy.
@@ -81,7 +73,6 @@ struct make_initializer_node
typedef typename unwrap_recursive<recursive_enabled_T>::type
public_T;
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
typedef boost::is_reference<public_T>
is_reference_content_t;
@@ -92,10 +83,6 @@ struct make_initializer_node
typedef typename boost::mpl::if_<is_reference_content_t, disable_overload<public_T>, public_T&& >::type
param2_T;
#else
typedef typename call_traits<public_T>::param_type
param_T;
#endif
public: // static functions
@@ -111,7 +98,6 @@ struct make_initializer_node
return BOOST_MPL_AUX_VALUE_WKND(index)::value; // which
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
static int initialize(void* dest, param2_T operand)
{
// This assert must newer trigger, because all the reference contents are
@@ -122,7 +108,6 @@ struct make_initializer_node
new(dest) value_T( boost::detail::variant::move(operand) );
return BOOST_MPL_AUX_VALUE_WKND(index)::value; // which
}
#endif
};
friend class initializer_node;
@@ -150,84 +135,6 @@ public: // static functions
};
#else // defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
#define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_PARAMS \
BOOST_VARIANT_ENUM_PARAMS(typename recursive_enabled_T) \
/**/
#define BOOST_VARIANT_AUX_PP_INITIALIZER_DEFINE_PARAM_T(N) \
typedef typename unwrap_recursive< \
BOOST_PP_CAT(recursive_enabled_T,N) \
>::type BOOST_PP_CAT(public_T,N); \
typedef typename call_traits< \
BOOST_PP_CAT(public_T,N) \
>::param_type BOOST_PP_CAT(param_T,N); \
/**/
# else // MSVC7 and below
#define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_PARAMS \
BOOST_VARIANT_ENUM_PARAMS(typename recursive_enabled_T) \
, BOOST_VARIANT_ENUM_PARAMS(typename param_T) \
/**/
#define BOOST_VARIANT_AUX_PP_INITIALIZER_DEFINE_PARAM_T(N) \
/**/
# endif // MSVC7 and below workaround
template < BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_PARAMS >
struct preprocessor_list_initializer
{
public: // static functions
#define BOOST_VARIANT_AUX_PP_INITIALIZE_FUNCTION(z,N,_) \
BOOST_VARIANT_AUX_PP_INITIALIZER_DEFINE_PARAM_T(N) \
static int initialize( \
void* dest \
, BOOST_PP_CAT(param_T,N) operand \
) \
{ \
typedef typename boost::detail::make_reference_content< \
BOOST_PP_CAT(recursive_enabled_T,N) \
>::type internal_T; \
\
new(dest) internal_T(operand); \
return (N); /*which*/ \
} \
/**/
BOOST_PP_REPEAT(
BOOST_VARIANT_LIMIT_TYPES
, BOOST_VARIANT_AUX_PP_INITIALIZE_FUNCTION
, _
)
#undef BOOST_VARIANT_AUX_PP_INITIALIZE_FUNCTION
};
# if defined(BOOST_MPL_CFG_MSVC_60_ETI_BUG)
#if !defined(BOOST_VARIANT_AUX_ECHO)
# define BOOST_VARIANT_AUX_ECHO(z,N,token) token
#endif
template <>
struct preprocessor_list_initializer<
BOOST_PP_ENUM(BOOST_VARIANT_LIMIT_TYPES, BOOST_VARIANT_AUX_ECHO, int)
, BOOST_PP_ENUM(BOOST_VARIANT_LIMIT_TYPES, BOOST_VARIANT_AUX_ECHO, const int)
>
{
};
# endif // BOOST_MPL_CFG_MSVC_60_ETI_BUG workaround
#endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
}} // namespace detail::variant
} // namespace boost
@@ -239,8 +146,6 @@ struct preprocessor_list_initializer<
// most appropriate to the current compiler.
//
#if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
#define BOOST_VARIANT_AUX_INITIALIZER_T( mpl_seq, typename_base ) \
::boost::mpl::iter_fold< \
mpl_seq \
@@ -254,39 +159,4 @@ struct preprocessor_list_initializer<
>::type::first \
/**/
#else // defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
#define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_ARGS(typename_base) \
BOOST_VARIANT_ENUM_PARAMS(typename_base) \
/**/
# else // MSVC7 and below
#define BOOST_VARIANT_AUX_PP_INITIALIZER_ENUM_PARAM_TYPE(z,N,T) \
::boost::call_traits< \
::boost::unwrap_recursive<BOOST_PP_CAT(T,N)>::type \
>::param_type \
/**/
#define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_ARGS(typename_base) \
BOOST_VARIANT_ENUM_PARAMS(typename_base) \
, BOOST_PP_ENUM( \
BOOST_VARIANT_LIMIT_TYPES \
, BOOST_VARIANT_AUX_PP_INITIALIZER_ENUM_PARAM_TYPE \
, typename_base \
) \
/**/
# endif // MSVC7 workaround
#define BOOST_VARIANT_AUX_INITIALIZER_T( mpl_seq, typename_base ) \
::boost::detail::variant::preprocessor_list_initializer< \
BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_ARGS(typename_base) \
> \
/**/
#endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
#endif // BOOST_VARIANT_DETAIL_INITIALIZER_HPP
@@ -3,8 +3,8 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2002-2003
// Eric Friedman, Itay Maman
// Copyright (c) 2002-2003 Eric Friedman, Itay Maman
// Copyright (c) 2013-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -13,14 +13,13 @@
#ifndef BOOST_VARIANT_DETAIL_MAKE_VARIANT_LIST_HPP
#define BOOST_VARIANT_DETAIL_MAKE_VARIANT_LIST_HPP
#include "boost/variant/variant_fwd.hpp"
#include <boost/variant/variant_fwd.hpp>
#include "boost/mpl/list.hpp"
#include "boost/preprocessor/cat.hpp"
#include "boost/preprocessor/enum.hpp"
#include <boost/mpl/list.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/enum.hpp>
namespace boost {
namespace detail { namespace variant {
namespace boost { namespace detail { namespace variant {
///////////////////////////////////////////////////////////////////////////////
// (detail) metafunction make_variant_list
@@ -31,30 +30,13 @@ namespace detail { namespace variant {
// Rationale: see class template convert_void (variant_fwd.hpp) and using-
// declaration workaround (below).
//
template < BOOST_VARIANT_ENUM_PARAMS(typename T) >
template < typename... T >
struct make_variant_list
{
public: // metafunction result
// [Define a macro to convert any void(NN) tags to mpl::void...]
# define BOOST_VARIANT_AUX_CONVERT_VOID(z, N,_) \
typename convert_void< BOOST_PP_CAT(T,N) >::type
// [...so that the specified types can be passed to mpl::list...]
typedef typename mpl::list<
BOOST_PP_ENUM(
BOOST_VARIANT_LIMIT_TYPES
, BOOST_VARIANT_AUX_CONVERT_VOID
, _
)
>::type type;
// [...and, finally, the conversion macro can be undefined:]
# undef BOOST_VARIANT_AUX_CONVERT_VOID
typedef typename mpl::list< T... >::type type;
};
}} // namespace detail::variant
} // namespace boost
}}} // namespace boost::detail::variant
#endif // BOOST_VARIANT_DETAIL_MAKE_VARIANT_LIST_HPP
+8 -44
View File
@@ -5,6 +5,7 @@
//
// Copyright (c) 2002-2003 Eric Friedman
// Copyright (c) 2002 by Andrei Alexandrescu
// Copyright (c) 2013-2026 Antony Polukhin
//
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
@@ -19,17 +20,13 @@
#ifndef BOOST_VARIANT_DETAIL_MOVE_HPP
#define BOOST_VARIANT_DETAIL_MOVE_HPP
#include <iterator> // for iterator_traits
#include <new> // for placement new
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <utility>
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
#include "boost/move/move.hpp"
namespace boost { namespace detail { namespace variant {
namespace boost {
namespace detail { namespace variant {
using boost::move;
using std::move;
//////////////////////////////////////////////////////////////////////////
// function template move_swap
@@ -38,47 +35,14 @@ using boost::move;
// types and on non-conforming compilers.
//
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) \
|| BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(2))
// [Indicate that move_swap by overload is disabled...]
#define BOOST_NO_MOVE_SWAP_BY_OVERLOAD
// [...and provide straight swap-by-move implementation:]
template <typename T>
inline void move_swap(T& lhs, T& rhs)
{
T tmp( boost::detail::variant::move(lhs) );
lhs = boost::detail::variant::move(rhs);
rhs = boost::detail::variant::move(tmp);
}
#else// !workaround
namespace detail { namespace move_swap {
template <typename T>
inline void swap(T& lhs, T& rhs)
{
T tmp( boost::detail::variant::move(lhs) );
lhs = boost::detail::variant::move(rhs);
rhs = boost::detail::variant::move(tmp);
}
}} // namespace detail::move_swap
template <typename T>
inline void move_swap(T& lhs, T& rhs)
{
using detail::move_swap::swap;
using std::swap;
swap(lhs, rhs);
}
#endif // workaround
}} // namespace detail::variant
} // namespace boost
}}} // namespace boost::detail::variant
#endif // BOOST_VARIANT_DETAIL_MOVE_HPP
@@ -0,0 +1,212 @@
// Boost.Varaint
// Contains multivisitors that are implemented via variadic templates and std::tuple
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2013-2024.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#ifndef BOOST_VARIANT_DETAIL_MULTIVISITORS_CPP11_BASED_HPP
#define BOOST_VARIANT_DETAIL_MULTIVISITORS_CPP11_BASED_HPP
#if defined(_MSC_VER)
# pragma once
#endif
#include <boost/variant/detail/apply_visitor_unary.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/type_traits/is_lvalue_reference.hpp>
#include <boost/core/enable_if.hpp>
#include <tuple>
namespace boost {
namespace detail { namespace variant {
// Implementing some of the C++14 features in C++11
template <std::size_t... I> class index_sequence {};
template <std::size_t N, std::size_t... I>
struct make_index_sequence
: make_index_sequence<N-1, N-1, I...>
{};
template <std::size_t... I>
struct make_index_sequence<0, I...>
: index_sequence<I...>
{};
template <typename T_, bool MoveSemantics_>
struct MoveableWrapper //Just a reference with some metadata
{
typedef T_ T;
static constexpr bool MoveSemantics = MoveSemantics_;
T& v;
};
template <typename Tp, bool MoveSemantics>
MoveableWrapper<Tp, MoveSemantics>
wrap(Tp& t)
{
return MoveableWrapper<Tp, MoveSemantics>{t};
}
template <typename Wrapper>
typename enable_if_c<Wrapper::MoveSemantics, typename Wrapper::T>::type
unwrap(Wrapper& w)
{
return std::move(w.v);
}
template <typename Wrapper>
typename disable_if_c<Wrapper::MoveSemantics, typename Wrapper::T>::type &
unwrap(Wrapper& w)
{
return w.v;
}
// Implementing some of the helper tuple methods
template <std::size_t... I, typename Tuple>
std::tuple<typename std::tuple_element<I + 1, Tuple>::type...>
tuple_tail_impl(const Tuple& tpl, index_sequence<I...>)
{
return std::tuple<
typename std::tuple_element<I + 1, Tuple>::type...
> (std::get<I + 1>(tpl)...);
}
template <typename Head, typename... Tail>
std::tuple<Tail...> tuple_tail(const std::tuple<Head, Tail...>& tpl)
{
return tuple_tail_impl(tpl, make_index_sequence<sizeof...(Tail)>());
}
// Forward declaration
template <typename Visitor, typename Visitables, typename... Values>
class one_by_one_visitor_and_value_referer;
template <typename Visitor, typename Visitables, typename... Values>
inline one_by_one_visitor_and_value_referer<Visitor, Visitables, Values... >
make_one_by_one_visitor_and_value_referer(
Visitor& visitor, Visitables visitables, std::tuple<Values...> values
)
{
return one_by_one_visitor_and_value_referer<Visitor, Visitables, Values... > (
visitor, visitables, values
);
}
template <typename Visitor, typename Visitables, typename... Values>
class one_by_one_visitor_and_value_referer
{
Visitor& visitor_;
std::tuple<Values...> values_;
Visitables visitables_;
public: // structors
one_by_one_visitor_and_value_referer(
Visitor& visitor, Visitables visitables, std::tuple<Values...> values
) BOOST_NOEXCEPT
: visitor_(visitor)
, values_(values)
, visitables_(visitables)
{}
public: // visitor interfaces
typedef typename Visitor::result_type result_type;
template <typename Value>
result_type operator()(Value&& value) const
{
return ::boost::apply_visitor(
make_one_by_one_visitor_and_value_referer(
visitor_,
tuple_tail(visitables_),
std::tuple_cat(values_, std::make_tuple(wrap<Value, ! ::boost::is_lvalue_reference<Value>::value>(value)))
)
, unwrap(std::get<0>(visitables_)) // getting Head element
);
}
private:
one_by_one_visitor_and_value_referer& operator=(const one_by_one_visitor_and_value_referer&);
};
template <typename Visitor, typename... Values>
class one_by_one_visitor_and_value_referer<Visitor, std::tuple<>, Values...>
{
Visitor& visitor_;
std::tuple<Values...> values_;
public:
one_by_one_visitor_and_value_referer(
Visitor& visitor, std::tuple<> /*visitables*/, std::tuple<Values...> values
) BOOST_NOEXCEPT
: visitor_(visitor)
, values_(values)
{}
typedef typename Visitor::result_type result_type;
template <class Tuple, std::size_t... I>
result_type do_call(Tuple t, index_sequence<I...>) const {
return visitor_(unwrap(std::get<I>(t))...);
}
template <typename Value>
result_type operator()(Value&& value) const
{
return do_call(
std::tuple_cat(values_, std::make_tuple(wrap<Value, ! ::boost::is_lvalue_reference<Value>::value>(value))),
make_index_sequence<sizeof...(Values) + 1>()
);
}
};
}} // namespace detail::variant
template <class Visitor, class T1, class T2, class T3, class... TN>
inline typename Visitor::result_type
apply_visitor(const Visitor& visitor, T1&& v1, T2&& v2, T3&& v3, TN&&... vn)
{
return ::boost::apply_visitor(
::boost::detail::variant::make_one_by_one_visitor_and_value_referer(
visitor,
std::make_tuple(
::boost::detail::variant::wrap<T2, ! ::boost::is_lvalue_reference<T2>::value>(v2),
::boost::detail::variant::wrap<T3, ! ::boost::is_lvalue_reference<T3>::value>(v3),
::boost::detail::variant::wrap<TN, ! ::boost::is_lvalue_reference<TN>::value>(vn)...
),
std::tuple<>()
),
std::forward<T1>(v1)
);
}
template <class Visitor, class T1, class T2, class T3, class... TN>
inline typename Visitor::result_type
apply_visitor(Visitor& visitor, T1&& v1, T2&& v2, T3&& v3, TN&&... vn)
{
return ::boost::apply_visitor(
::boost::detail::variant::make_one_by_one_visitor_and_value_referer(
visitor,
std::make_tuple(
::boost::detail::variant::wrap<T2, ! ::boost::is_lvalue_reference<T2>::value>(v2),
::boost::detail::variant::wrap<T3, ! ::boost::is_lvalue_reference<T3>::value>(v3),
::boost::detail::variant::wrap<TN, ! ::boost::is_lvalue_reference<TN>::value>(vn)...
),
std::tuple<>()
),
std::forward<T1>(v1)
);
}
} // namespace boost
#endif // BOOST_VARIANT_DETAIL_MULTIVISITORS_CPP11_BASED_HPP
@@ -0,0 +1,152 @@
// Boost.Varaint
// Contains multivisitors that are implemented via variadic templates, std::tuple
// and decltype(auto)
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2013-2014.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
#ifndef BOOST_VARIANT_DETAIL_MULTIVISITORS_CPP14_BASED_HPP
#define BOOST_VARIANT_DETAIL_MULTIVISITORS_CPP14_BASED_HPP
#if defined(_MSC_VER)
# pragma once
#endif
#include <tuple>
namespace boost {
namespace detail { namespace variant {
// Forward declaration
template <typename Visitor, typename Visitables, typename... Values>
class one_by_one_visitor_and_value_referer_cpp14;
template <typename Visitor, typename Visitables, typename... Values>
inline one_by_one_visitor_and_value_referer_cpp14<Visitor, Visitables, Values... >
make_one_by_one_visitor_and_value_referer_cpp14(
Visitor& visitor, Visitables visitables, std::tuple<Values...> values
)
{
return one_by_one_visitor_and_value_referer_cpp14<Visitor, Visitables, Values... > (
visitor, visitables, values
);
}
template <typename Visitor, typename Visitables, typename... Values>
class one_by_one_visitor_and_value_referer_cpp14
{
Visitor& visitor_;
std::tuple<Values...> values_;
Visitables visitables_;
public: // structors
one_by_one_visitor_and_value_referer_cpp14(
Visitor& visitor, Visitables visitables, std::tuple<Values...> values
) BOOST_NOEXCEPT
: visitor_(visitor)
, values_(values)
, visitables_(visitables)
{}
public: // visitor interfaces
template <typename Value>
decltype(auto) operator()(Value&& value) const
{
return ::boost::apply_visitor(
make_one_by_one_visitor_and_value_referer_cpp14(
visitor_,
tuple_tail(visitables_),
std::tuple_cat(values_, std::make_tuple(wrap<Value, ! ::boost::is_lvalue_reference<Value>::value>(value)))
)
, unwrap(std::get<0>(visitables_)) // getting Head element
);
}
private:
one_by_one_visitor_and_value_referer_cpp14& operator=(const one_by_one_visitor_and_value_referer_cpp14&);
};
template <typename Visitor, typename... Values>
class one_by_one_visitor_and_value_referer_cpp14<Visitor, std::tuple<>, Values...>
{
Visitor& visitor_;
std::tuple<Values...> values_;
public:
one_by_one_visitor_and_value_referer_cpp14(
Visitor& visitor, std::tuple<> /*visitables*/, std::tuple<Values...> values
) BOOST_NOEXCEPT
: visitor_(visitor)
, values_(values)
{}
template <class Tuple, std::size_t... I>
decltype(auto) do_call(Tuple t, index_sequence<I...>) const {
return visitor_(unwrap(std::get<I>(t))...);
}
template <typename Value>
decltype(auto) operator()(Value&& value) const
{
return do_call(
std::tuple_cat(values_, std::make_tuple(wrap<Value, ! ::boost::is_lvalue_reference<Value>::value>(value))),
make_index_sequence<sizeof...(Values) + 1>()
);
}
};
}} // namespace detail::variant
template <class Visitor, class T1, class T2, class T3, class... TN>
inline decltype(auto) apply_visitor(const Visitor& visitor, T1&& v1, T2&& v2, T3&& v3, TN&&... vn,
typename boost::disable_if<
boost::detail::variant::has_result_type<Visitor>,
bool
>::type = true)
{
return boost::apply_visitor(
::boost::detail::variant::make_one_by_one_visitor_and_value_referer_cpp14(
visitor,
std::make_tuple(
::boost::detail::variant::wrap<T2, ! ::boost::is_lvalue_reference<T2>::value>(v2),
::boost::detail::variant::wrap<T3, ! ::boost::is_lvalue_reference<T3>::value>(v3),
::boost::detail::variant::wrap<TN, ! ::boost::is_lvalue_reference<TN>::value>(vn)...
),
std::tuple<>()
),
std::forward<T1>(v1)
);
}
template <class Visitor, class T1, class T2, class T3, class... TN>
inline decltype(auto) apply_visitor(Visitor& visitor, T1&& v1, T2&& v2, T3&& v3, TN&&... vn,
typename boost::disable_if<
boost::detail::variant::has_result_type<Visitor>,
bool
>::type = true)
{
return ::boost::apply_visitor(
::boost::detail::variant::make_one_by_one_visitor_and_value_referer_cpp14(
visitor,
std::make_tuple(
::boost::detail::variant::wrap<T2, ! ::boost::is_lvalue_reference<T2>::value>(v2),
::boost::detail::variant::wrap<T3, ! ::boost::is_lvalue_reference<T3>::value>(v3),
::boost::detail::variant::wrap<TN, ! ::boost::is_lvalue_reference<TN>::value>(vn)...
),
std::tuple<>()
),
std::forward<T1>(v1)
);
}
} // namespace boost
#endif // BOOST_VARIANT_DETAIL_MULTIVISITORS_CPP14_BASED_HPP
+1 -38
View File
@@ -15,13 +15,7 @@
#ifndef BOOST_VARIANT_DETAIL_OVER_SEQUENCE_HPP
#define BOOST_VARIANT_DETAIL_OVER_SEQUENCE_HPP
#include "boost/mpl/aux_/config/ctps.hpp"
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
# include "boost/mpl/eval_if.hpp"
# include "boost/mpl/bool.hpp"
# include "boost/mpl/identity.hpp"
# include "boost/type.hpp"
#endif
#include <boost/mpl/aux_/config/ctps.hpp>
namespace boost {
@@ -44,7 +38,6 @@ struct over_sequence
// Indicates whether the specified type is of form over_sequence<...> or not.
//
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename T>
struct is_over_sequence
@@ -58,36 +51,6 @@ struct is_over_sequence< over_sequence<Types> >
{
};
#else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
typedef char (&yes_over_sequence_t)[1];
typedef char (&no_over_sequence_t)[2];
no_over_sequence_t is_over_sequence_test(...);
template<typename T>
yes_over_sequence_t is_over_sequence_test(
type< ::boost::detail::variant::over_sequence<T> >
);
template<typename T>
struct is_over_sequence_impl
{
BOOST_STATIC_CONSTANT(bool, value = (
sizeof(is_over_sequence_test(type<T>()))
== sizeof(yes_over_sequence_t)
));
};
template <typename T>
struct is_over_sequence
: mpl::bool_<
::boost::detail::variant::is_over_sequence_impl<T>::value
>
{
};
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
}} // namespace detail::variant
} // namespace boost
+46
View File
@@ -0,0 +1,46 @@
//-----------------------------------------------------------------------------
// boost variant/detail/std_hash.hpp header file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2018-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_VARIANT_DETAIL_STD_HASH_HPP
#define BOOST_VARIANT_DETAIL_STD_HASH_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <boost/variant/variant_fwd.hpp>
#include <boost/variant/detail/hash_variant.hpp>
///////////////////////////////////////////////////////////////////////////////
// macro BOOST_VARIANT_DO_NOT_SPECIALIZE_STD_HASH
//
// Define this macro if you do not wish to have a std::hash specialization for
// boost::variant.
#if !defined(BOOST_VARIANT_DO_NOT_SPECIALIZE_STD_HASH) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
#include <functional> // for std::hash
namespace std {
template < BOOST_VARIANT_ENUM_PARAMS(typename T) >
struct hash<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) > > {
std::size_t operator()(const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& val) const {
return ::boost::hash_value(val);
}
};
}
#endif // #if !defined(BOOST_VARIANT_DO_NOT_SPECIALIZE_STD_HASH) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
#endif // BOOST_VARIANT_DETAIL_STD_HASH_HPP
+25 -90
View File
@@ -1,8 +1,3 @@
#if !defined(BOOST_PP_IS_ITERATING)
///// header body
//-----------------------------------------------------------------------------
// boost variant/detail/substitute.hpp header file
// See http://www.boost.org for updates, documentation, and revision history.
@@ -18,24 +13,20 @@
#ifndef BOOST_VARIANT_DETAIL_SUBSTITUTE_HPP
#define BOOST_VARIANT_DETAIL_SUBSTITUTE_HPP
#include "boost/mpl/aux_/config/ctps.hpp"
#include <boost/mpl/aux_/config/ctps.hpp>
#include "boost/variant/detail/substitute_fwd.hpp"
#include "boost/mpl/aux_/lambda_arity_param.hpp"
#include "boost/mpl/aux_/preprocessor/params.hpp"
#include "boost/mpl/aux_/preprocessor/repeat.hpp"
#include "boost/mpl/int_fwd.hpp"
#include "boost/mpl/limits/arity.hpp"
#include "boost/preprocessor/cat.hpp"
#include "boost/preprocessor/empty.hpp"
#include "boost/preprocessor/arithmetic/inc.hpp"
#include "boost/preprocessor/iterate.hpp"
#include <boost/variant/detail/substitute_fwd.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/mpl/aux_/lambda_arity_param.hpp>
#include <boost/mpl/aux_/preprocessor/params.hpp>
#include <boost/mpl/aux_/preprocessor/repeat.hpp>
#include <boost/mpl/int_fwd.hpp>
#include <boost/mpl/limits/arity.hpp>
#include <boost/preprocessor/empty.hpp>
namespace boost {
namespace detail { namespace variant {
#if !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
///////////////////////////////////////////////////////////////////////////////
// (detail) metafunction substitute
//
@@ -125,58 +116,23 @@ struct substitute<
// template expression (i.e., F<...>) specializations
//
#define BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF_IMPL(N) \
typedef typename substitute< \
BOOST_PP_CAT(U,N), Dest, Source \
>::type BOOST_PP_CAT(u,N); \
/**/
#define BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF(z, N, _) \
BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF_IMPL( BOOST_PP_INC(N) ) \
/**/
#define BOOST_PP_ITERATION_LIMITS (0,BOOST_MPL_LIMIT_METAFUNCTION_ARITY)
#define BOOST_PP_FILENAME_1 "boost/variant/detail/substitute.hpp"
#include BOOST_PP_ITERATE()
#undef BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF_IMPL
#undef BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF
#endif // !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
}} // namespace detail::variant
} // namespace boost
#endif // BOOST_VARIANT_DETAIL_SUBSTITUTE_HPP
///// iteration, depth == 1
#elif BOOST_PP_ITERATION_DEPTH() == 1
#define i BOOST_PP_FRAME_ITERATION(1)
#if i > 0
//
// template specializations
//
template <
template < BOOST_MPL_PP_PARAMS(i,typename P) > class T
, BOOST_MPL_PP_PARAMS(i,typename U)
template <typename...> class F
, typename... Ts
, typename Dest
, typename Source
BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(typename Arity)
>
struct substitute<
T< BOOST_MPL_PP_PARAMS(i,U) >
F<Ts...>
, Dest
, Source
BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<( i )>)
BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(Arity)
>
{
private:
BOOST_MPL_PP_REPEAT(i, BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF, _)
public:
typedef T< BOOST_MPL_PP_PARAMS(i,u) > type;
typedef F<typename substitute<
Ts, Dest, Source
>::type...> type;
};
//
@@ -184,35 +140,12 @@ public:
//
template <
typename R
, BOOST_MPL_PP_PARAMS(i,typename U)
, typename... A
, typename Dest
, typename Source
>
struct substitute<
R (*)( BOOST_MPL_PP_PARAMS(i,U) )
, Dest
, Source
BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>)
>
{
private:
typedef typename substitute< R, Dest, Source >::type r;
BOOST_MPL_PP_REPEAT(i, BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF, _)
public:
typedef r (*type)( BOOST_MPL_PP_PARAMS(i,u) );
};
#elif i == 0
//
// zero-arg function specialization
//
template <
typename R, typename Dest, typename Source
>
struct substitute<
R (*)( void )
R (*)(A...)
, Dest
, Source
BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>)
@@ -222,10 +155,12 @@ private:
typedef typename substitute< R, Dest, Source >::type r;
public:
typedef r (*type)( void );
typedef r (*type)(typename substitute<
A, Dest, Source
>::type...);
};
#endif // i
}} // namespace detail::variant
} // namespace boost
#undef i
#endif // BOOST_PP_IS_ITERATING
#endif // BOOST_VARIANT_DETAIL_SUBSTITUTE_HPP
@@ -13,31 +13,17 @@
#ifndef BOOST_VARIANT_DETAIL_SUBSTITUTE_FWD_HPP
#define BOOST_VARIANT_DETAIL_SUBSTITUTE_FWD_HPP
#include "boost/mpl/aux_/lambda_arity_param.hpp"
#include "boost/mpl/aux_/template_arity.hpp"
#include "boost/mpl/int_fwd.hpp"
#include <boost/mpl/aux_/lambda_arity_param.hpp>
#include <boost/mpl/aux_/template_arity.hpp>
#include <boost/mpl/int_fwd.hpp>
///////////////////////////////////////////////////////////////////////////////
// BOOST_VARIANT_DETAIL_NO_SUBSTITUTE
//
// Defined if 'substitute' is not implementable on the current compiler.
//
#include "boost/mpl/aux_/config/ctps.hpp"
#include "boost/mpl/aux_/config/ttp.hpp"
#if defined(BOOST_NO_TEMPLATE_TEMPLATE_PARAMETERS) \
|| defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
&& !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
# define BOOST_VARIANT_DETAIL_NO_SUBSTITUTE
#endif
#include <boost/mpl/aux_/config/ctps.hpp>
#include <boost/mpl/aux_/config/ttp.hpp>
namespace boost {
namespace detail { namespace variant {
#if !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
///////////////////////////////////////////////////////////////////////////////
// metafunction substitute
//
@@ -51,8 +37,6 @@ template <
>
struct substitute;
#endif // !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
}} // namespace detail::variant
} // namespace boost
+9 -21
View File
@@ -15,10 +15,8 @@
#include <iosfwd> // for std::basic_ostream forward declare
#include "boost/variant/variant_fwd.hpp"
#include "boost/detail/templated_streams.hpp"
#include "boost/variant/static_visitor.hpp"
#include <boost/variant/variant_fwd.hpp>
#include <boost/variant/static_visitor.hpp>
namespace boost {
@@ -29,14 +27,9 @@ namespace boost {
//
// forward declare (allows output of embedded variant< variant< ... >, ... >)
template <
BOOST_TEMPLATED_STREAM_ARGS(E,T)
BOOST_TEMPLATED_STREAM_COMMA
BOOST_VARIANT_ENUM_PARAMS(typename U)
>
inline BOOST_TEMPLATED_STREAM(ostream, E,T)& operator<<(
BOOST_TEMPLATED_STREAM(ostream, E,T)& out
, const variant< BOOST_VARIANT_ENUM_PARAMS(U) >& rhs
template <class CharT, class Trait, typename... U>
inline std::basic_ostream<CharT, Trait>& operator<<(
std::basic_ostream<CharT, Trait>& out, const variant<U...>& rhs
);
namespace detail { namespace variant {
@@ -71,18 +64,13 @@ private:
}} // namespace detail::variant
template <
BOOST_TEMPLATED_STREAM_ARGS(E,T)
BOOST_TEMPLATED_STREAM_COMMA
BOOST_VARIANT_ENUM_PARAMS(typename U)
>
inline BOOST_TEMPLATED_STREAM(ostream, E,T)& operator<<(
BOOST_TEMPLATED_STREAM(ostream, E,T)& out
, const variant< BOOST_VARIANT_ENUM_PARAMS(U) >& rhs
template <class CharT, class Trait, typename... U>
inline std::basic_ostream<CharT, Trait>& operator<<(
std::basic_ostream<CharT, Trait>& out, const variant<U...>& rhs
)
{
detail::variant::printer<
BOOST_TEMPLATED_STREAM(ostream, E,T)
std::basic_ostream<CharT, Trait>
> visitor(out);
rhs.apply_visitor(visitor);
@@ -13,31 +13,30 @@
#ifndef BOOST_VARIANT_DETAIL_VISITATION_IMPL_HPP
#define BOOST_VARIANT_DETAIL_VISITATION_IMPL_HPP
#include "boost/config.hpp"
#include <boost/config.hpp>
#include "boost/variant/detail/backup_holder.hpp"
#include "boost/variant/detail/cast_storage.hpp"
#include "boost/variant/detail/forced_return.hpp"
#include "boost/variant/detail/generic_result_type.hpp"
#include <boost/variant/detail/backup_holder.hpp>
#include <boost/variant/detail/cast_storage.hpp>
#include <boost/variant/detail/forced_return.hpp>
#include <boost/variant/variant_fwd.hpp>
#include "boost/assert.hpp"
#include "boost/mpl/eval_if.hpp"
#include "boost/mpl/bool.hpp"
#include "boost/mpl/identity.hpp"
#include "boost/mpl/int.hpp"
#include "boost/mpl/next.hpp"
#include "boost/mpl/deref.hpp"
#include "boost/mpl/or.hpp"
#include "boost/preprocessor/cat.hpp"
#include "boost/preprocessor/inc.hpp"
#include "boost/preprocessor/repeat.hpp"
#include "boost/type_traits/is_same.hpp"
#include "boost/type_traits/has_nothrow_copy.hpp"
#include "boost/type_traits/is_nothrow_move_constructible.hpp"
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/next.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/or.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/inc.hpp>
#include <boost/preprocessor/repeat.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/has_nothrow_copy.hpp>
#include <boost/type_traits/is_nothrow_move_constructible.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning (push)
# pragma warning (disable : 4702) //unreachable code
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning (push)
# pragma warning (disable : 4702) //unreachable code
#endif
///////////////////////////////////////////////////////////////////////////////
@@ -47,8 +46,11 @@
// and potentially increase runtime performance. (TODO: Investigate further.)
//
#if !defined(BOOST_VARIANT_VISITATION_UNROLLING_LIMIT)
# include <boost/mpl/limits/list.hpp>
# define BOOST_VARIANT_VISITATION_UNROLLING_LIMIT \
BOOST_VARIANT_LIMIT_TYPES
BOOST_MPL_LIMIT_LIST_SIZE
#endif
namespace boost {
@@ -67,7 +69,6 @@ struct apply_visitor_unrolled {};
// "Never ending" iterator range facilitates visitation_impl unrolling.
//
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename Iter, typename LastIter>
struct visitation_impl_step
@@ -87,29 +88,6 @@ struct visitation_impl_step< LastIter,LastIter >
typedef visitation_impl_step next;
};
#else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename Iter, typename LastIter>
struct visitation_impl_step
{
typedef typename mpl::eval_if<
is_same<Iter, LastIter>
, mpl::identity<apply_visitor_unrolled>
, Iter
>::type type;
typedef typename mpl::eval_if<
is_same<type, apply_visitor_unrolled> //is_same<Iter, LastIter>
, mpl::identity<LastIter>
, mpl::next<Iter>
>::type next_iter;
typedef visitation_impl_step<
next_iter, LastIter
> next;
};
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
///////////////////////////////////////////////////////////////////////////////
// (detail) function template visitation_impl_invoke
@@ -118,8 +96,7 @@ struct visitation_impl_step
//
template <typename Visitor, typename VoidPtrCV, typename T>
inline
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
inline typename Visitor::result_type
visitation_impl_invoke_impl(
int, Visitor& visitor, VoidPtrCV storage, T*
, mpl::true_// never_uses_backup
@@ -131,8 +108,7 @@ visitation_impl_invoke_impl(
}
template <typename Visitor, typename VoidPtrCV, typename T>
inline
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
inline typename Visitor::result_type
visitation_impl_invoke_impl(
int internal_which, Visitor& visitor, VoidPtrCV storage, T*
, mpl::false_// never_uses_backup
@@ -153,8 +129,7 @@ visitation_impl_invoke_impl(
}
template <typename Visitor, typename VoidPtrCV, typename T, typename NoBackupFlag>
inline
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
inline typename Visitor::result_type
visitation_impl_invoke(
int internal_which, Visitor& visitor, VoidPtrCV storage, T* t
, NoBackupFlag
@@ -174,12 +149,10 @@ visitation_impl_invoke(
}
template <typename Visitor, typename VoidPtrCV, typename NBF>
inline
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
inline typename Visitor::result_type
visitation_impl_invoke(int, Visitor&, VoidPtrCV, apply_visitor_unrolled*, NBF, long)
{
// should never be here at runtime:
BOOST_ASSERT(false);
// should never be here at runtime!
typedef typename Visitor::result_type result_type;
return ::boost::detail::variant::forced_return< result_type >();
}
@@ -195,16 +168,14 @@ template <
, typename Visitor, typename VPCV
, typename NBF
>
inline
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
inline typename Visitor::result_type
visitation_impl(
int, int, Visitor&, VPCV
, mpl::true_ // is_apply_visitor_unrolled
, NBF, W* = 0, S* = 0
, NBF, W* = nullptr, S* = nullptr
)
{
// should never be here at runtime:
BOOST_ASSERT(false);
// should never be here at runtime!
typedef typename Visitor::result_type result_type;
return ::boost::detail::variant::forced_return< result_type >();
}
@@ -214,14 +185,13 @@ template <
, typename Visitor, typename VoidPtrCV
, typename NoBackupFlag
>
inline
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename Visitor::result_type)
BOOST_FORCEINLINE typename Visitor::result_type
visitation_impl(
const int internal_which, const int logical_which
, Visitor& visitor, VoidPtrCV storage
, mpl::false_ // is_apply_visitor_unrolled
, NoBackupFlag no_backup_flag
, Which* = 0, step0* = 0
, Which* = nullptr, step0* = nullptr
)
{
// Typedef apply_visitor_unrolled steps and associated types...
@@ -276,7 +246,7 @@ visitation_impl(
typedef typename is_same< next_type,apply_visitor_unrolled >::type
is_apply_visitor_unrolled;
return visitation_impl(
return detail::variant::visitation_impl(
internal_which, logical_which
, visitor, storage
, is_apply_visitor_unrolled()
@@ -288,8 +258,8 @@ visitation_impl(
}} // namespace detail::variant
} // namespace boost
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning(pop)
#endif
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning(pop)
#endif
#endif // BOOST_VARIANT_DETAIL_VISITATION_IMPL_HPP
+258 -73
View File
@@ -3,8 +3,8 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2003
// Eric Friedman, Itay Maman
// Copyright (c) 2003 Eric Friedman, Itay Maman
// Copyright (c) 2014-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -15,40 +15,46 @@
#include <exception>
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
#include "boost/throw_exception.hpp"
#include "boost/utility/addressof.hpp"
#include "boost/variant/variant_fwd.hpp"
#include <boost/config.hpp>
#include <boost/core/addressof.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/static_assert.hpp>
#include <boost/throw_exception.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/variant/detail/element_index.hpp>
#include <boost/variant/detail/move.hpp>
#include "boost/type_traits/add_reference.hpp"
#include "boost/type_traits/add_pointer.hpp"
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
# include "boost/mpl/bool.hpp"
# include "boost/mpl/or.hpp"
# include "boost/type_traits/is_same.hpp"
#endif
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/add_pointer.hpp>
#include <boost/type_traits/is_lvalue_reference.hpp>
namespace boost {
#if defined(BOOST_CLANG)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wweak-vtables"
#endif
//////////////////////////////////////////////////////////////////////////
// class bad_get
//
// The exception thrown in the event of a failed get of a value.
//
class bad_get
class BOOST_SYMBOL_VISIBLE bad_get
: public std::exception
{
public: // std::exception implementation
virtual const char * what() const BOOST_NOEXCEPT_OR_NOTHROW
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
{
return "boost::bad_get: "
"failed value get using boost::get";
}
};
#if defined(BOOST_CLANG)
# pragma clang diagnostic pop
#endif
//////////////////////////////////////////////////////////////////////////
// function template get<T>
@@ -78,71 +84,44 @@ public: // visitor typedefs
public: // visitor interfaces
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
pointer operator()(reference operand) const
pointer operator()(reference operand) const BOOST_NOEXCEPT
{
return boost::addressof(operand);
}
template <typename U>
pointer operator()(const U&) const
pointer operator()(const U&) const BOOST_NOEXCEPT
{
return static_cast<pointer>(0);
}
#else // MSVC6
private: // helpers, for visitor interfaces (below)
pointer execute_impl(reference operand, mpl::true_) const
{
return boost::addressof(operand);
}
template <typename U>
pointer execute_impl(const U& operand, mpl::false_) const
{
return static_cast<pointer>(0);
}
public: // visitor interfaces
template <typename U>
pointer operator()(U& operand) const
{
// MSVC6 finds normal implementation (above) ambiguous,
// so we must explicitly disambiguate
typedef typename mpl::or_<
is_same<U, T>
, is_same<const U, T>
>::type U_is_T;
return execute_impl(operand, U_is_T());
}
#endif // MSVC6 workaround
};
}} // namespace detail::variant
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0551))
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t) \
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
#else
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t) \
, t* = 0
#ifndef BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE
# if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x0551))
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t)
# else
# if defined(BOOST_NO_CXX11_NULLPTR)
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t) \
, t* = 0
# else
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t) \
, t* = nullptr
# endif
# endif
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// relaxed_get<U>(variant) methods
//
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<U>::type
get(
relaxed_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
) BOOST_NOEXCEPT
{
typedef typename add_pointer<U>::type U_ptr;
if (!operand) return static_cast<U_ptr>(0);
@@ -154,10 +133,10 @@ get(
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<const U>::type
get(
relaxed_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
) BOOST_NOEXCEPT
{
typedef typename add_pointer<const U>::type U_ptr;
if (!operand) return static_cast<U_ptr>(0);
@@ -169,19 +148,209 @@ get(
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<U>::type
get(
relaxed_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
typedef typename add_pointer<U>::type U_ptr;
U_ptr result = get<U>(&operand);
U_ptr result = relaxed_get<U>(boost::addressof(operand));
if (!result)
boost::throw_exception(bad_get());
return *result;
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<const U>::type
relaxed_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
typedef typename add_pointer<const U>::type U_ptr;
U_ptr result = relaxed_get<const U>(boost::addressof(operand));
if (!result)
boost::throw_exception(bad_get());
return *result;
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
#if defined(BOOST_MSVC) && (_MSC_VER < 1900) // MSVC-2014 has fixed the incorrect diagnostics.
# pragma warning(push)
# pragma warning(disable: 4172) // returning address of local variable or temporary
#endif
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
U&&
relaxed_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >&& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
typedef typename add_pointer<U>::type U_ptr;
U_ptr result = relaxed_get<U>(boost::addressof(operand));
if (!result)
boost::throw_exception(bad_get());
return static_cast<U&&>(*result);
}
#if defined(BOOST_MSVC) && (_MSC_VER < 1900)
# pragma warning(pop)
#endif
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// strict_get<U>(variant) methods
//
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<U>::type
strict_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT_MSG(
(boost::detail::variant::holds_element<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >, U >::value),
"boost::variant does not contain specified type U, "
"call to boost::get<U>(boost::variant<T...>*) will always return NULL"
);
return relaxed_get<U>(operand);
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<const U>::type
strict_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT_MSG(
(boost::detail::variant::holds_element<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >, const U >::value),
"boost::variant does not contain specified type U, "
"call to boost::get<U>(const boost::variant<T...>*) will always return NULL"
);
return relaxed_get<U>(operand);
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<U>::type
strict_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
BOOST_STATIC_ASSERT_MSG(
(boost::detail::variant::holds_element<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >, U >::value),
"boost::variant does not contain specified type U, "
"call to boost::get<U>(boost::variant<T...>&) will always throw boost::bad_get exception"
);
return relaxed_get<U>(operand);
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<const U>::type
strict_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
BOOST_STATIC_ASSERT_MSG(
(boost::detail::variant::holds_element<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >, const U >::value),
"boost::variant does not contain specified type U, "
"call to boost::get<U>(const boost::variant<T...>&) will always throw boost::bad_get exception"
);
return relaxed_get<U>(operand);
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
U&&
strict_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >&& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
BOOST_STATIC_ASSERT_MSG(
(!boost::is_lvalue_reference<U>::value),
"remove ampersand '&' from template type U in boost::get<U>(boost::variant<T...>&&) "
);
BOOST_STATIC_ASSERT_MSG(
(boost::detail::variant::holds_element<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >, U >::value),
"boost::variant does not contain specified type U, "
"call to boost::get<U>(const boost::variant<T...>&) will always throw boost::bad_get exception"
);
return relaxed_get<U>(detail::variant::move(operand));
}
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// get<U>(variant) methods
//
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<U>::type
get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
{
#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
return relaxed_get<U>(operand);
#else
return strict_get<U>(operand);
#endif
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<const U>::type
get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
{
#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
return relaxed_get<U>(operand);
#else
return strict_get<U>(operand);
#endif
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<U>::type
get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
return relaxed_get<U>(operand);
#else
return strict_get<U>(operand);
#endif
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<const U>::type
@@ -190,14 +359,30 @@ get(
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
typedef typename add_pointer<const U>::type U_ptr;
U_ptr result = get<const U>(&operand);
if (!result)
boost::throw_exception(bad_get());
return *result;
#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
return relaxed_get<U>(operand);
#else
return strict_get<U>(operand);
#endif
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
U&&
get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >&& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
return relaxed_get<U>(detail::variant::move(operand));
#else
return strict_get<U>(detail::variant::move(operand));
#endif
}
#endif
} // namespace boost
#endif // BOOST_VARIANT_GET_HPP
+7 -122
View File
@@ -3,7 +3,7 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2013.
// Copyright (c) 2013-2026 Antony Polukhin.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
@@ -12,132 +12,17 @@
#ifndef BOOST_VARIANT_MULTIVISITORS_HPP
#define BOOST_VARIANT_MULTIVISITORS_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#if defined(_MSC_VER)
# pragma once
#endif
#include <boost/variant.hpp>
#include <boost/bind.hpp>
#include <boost/config.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/preprocessor/repetition.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/arithmetic/add.hpp>
#include <boost/preprocessor/arithmetic/sub.hpp>
#ifndef BOOST_VARAINT_MAX_MULTIVIZITOR_PARAMS
# define BOOST_VARAINT_MAX_MULTIVIZITOR_PARAMS 4
#include <boost/variant/detail/multivisitors_cpp11_based.hpp>
#if !defined(BOOST_NO_CXX14_DECLTYPE_AUTO) && !defined(BOOST_NO_CXX11_DECLTYPE_N3276)
# include <boost/variant/detail/multivisitors_cpp14_based.hpp>
#endif
namespace boost {
namespace detail { namespace variant {
template <class VisitorT, class Visitable1T, class Visitable2T>
struct two_variables_holder {
private:
VisitorT& visitor_;
Visitable1T& visitable1_;
Visitable2T& visitable2_;
// required to supress warnings and enshure that we do not copy
// this visitor
two_variables_holder& operator=(const two_variables_holder&);
public:
typedef BOOST_DEDUCED_TYPENAME VisitorT::result_type result_type;
explicit two_variables_holder(VisitorT& visitor, Visitable1T& visitable1, Visitable2T& visitable2) BOOST_NOEXCEPT
: visitor_(visitor)
, visitable1_(visitable1)
, visitable2_(visitable2)
{}
#define BOOST_VARIANT_OPERATOR_BEG() \
return ::boost::apply_visitor( \
::boost::bind<result_type>(boost::ref(visitor_), _1, _2 \
/**/
#define BOOST_VARIANT_OPERATOR_END() \
), visitable1_, visitable2_); \
/**/
#define BOOST_VARANT_VISITORS_VARIABLES_PRINTER(z, n, data) \
BOOST_PP_COMMA() boost::ref( BOOST_PP_CAT(vis, n) ) \
/**/
#define BOOST_VARIANT_VISIT(z, n, data) \
template <BOOST_PP_ENUM_PARAMS(BOOST_PP_ADD(n, 1), class VisitableUnwrapped)> \
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type) operator()( \
BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ADD(n, 1), VisitableUnwrapped, & vis) \
) const \
{ \
BOOST_VARIANT_OPERATOR_BEG() \
BOOST_PP_REPEAT(BOOST_PP_ADD(n, 1), BOOST_VARANT_VISITORS_VARIABLES_PRINTER, ~) \
BOOST_VARIANT_OPERATOR_END() \
} \
/**/
BOOST_PP_REPEAT( BOOST_PP_SUB(BOOST_VARAINT_MAX_MULTIVIZITOR_PARAMS, 2), BOOST_VARIANT_VISIT, ~)
#undef BOOST_VARIANT_OPERATOR_BEG
#undef BOOST_VARIANT_OPERATOR_END
#undef BOOST_VARANT_VISITORS_VARIABLES_PRINTER
#undef BOOST_VARIANT_VISIT
};
template <class VisitorT, class Visitable1T, class Visitable2T>
inline two_variables_holder<VisitorT, Visitable1T, Visitable2T> make_two_variables_holder(
VisitorT& visitor, Visitable1T& visitable1, Visitable2T& visitable2
) BOOST_NOEXCEPT
{
return two_variables_holder<VisitorT, Visitable1T, Visitable2T>(visitor, visitable1, visitable2);
}
template <class VisitorT, class Visitable1T, class Visitable2T>
inline two_variables_holder<const VisitorT, Visitable1T, Visitable2T> make_two_variables_holder(
const VisitorT& visitor, Visitable1T& visitable1, Visitable2T& visitable2
) BOOST_NOEXCEPT
{
return two_variables_holder<const VisitorT, Visitable1T, Visitable2T>(visitor, visitable1, visitable2);
}
}} // namespace detail::variant
#define BOOST_VARIANT_APPLY_VISITOR_BEG() \
return ::boost::apply_visitor( \
boost::detail::variant::make_two_variables_holder(visitor, var0 , var1), \
var2 \
/**/
#define BOOST_VARIANT_APPLY_VISITOR_END() \
); \
/**/
#define BOOST_VARANT_VISITORS_VARIABLES_PRINTER(z, n, data) \
BOOST_PP_COMMA() BOOST_PP_CAT(var, BOOST_PP_ADD(n, 3)) \
/**/
#define BOOST_VARIANT_VISIT(z, n, data) \
template <class Visitor BOOST_PP_COMMA() BOOST_PP_ENUM_PARAMS(BOOST_PP_ADD(n, 3), class T)> \
inline BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(BOOST_DEDUCED_TYPENAME Visitor::result_type) apply_visitor( \
data BOOST_PP_COMMA() BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ADD(n, 3), T, & var) \
) \
{ \
BOOST_VARIANT_APPLY_VISITOR_BEG() \
BOOST_PP_REPEAT(n, BOOST_VARANT_VISITORS_VARIABLES_PRINTER, ~) \
BOOST_VARIANT_APPLY_VISITOR_END() \
} \
/**/
BOOST_PP_REPEAT( BOOST_PP_SUB(BOOST_VARAINT_MAX_MULTIVIZITOR_PARAMS, 2), BOOST_VARIANT_VISIT, const Visitor& visitor)
BOOST_PP_REPEAT( BOOST_PP_SUB(BOOST_VARAINT_MAX_MULTIVIZITOR_PARAMS, 2), BOOST_VARIANT_VISIT, Visitor& visitor)
#undef BOOST_VARIANT_APPLY_VISITOR_BEG
#undef BOOST_VARIANT_APPLY_VISITOR_END
#undef BOOST_VARANT_VISITORS_VARIABLES_PRINTER
#undef BOOST_VARIANT_VISIT
} // namespace boost
#endif // BOOST_VARIANT_MULTIVISITORS_HPP
+352
View File
@@ -0,0 +1,352 @@
//-----------------------------------------------------------------------------
// boost variant/polymorphic_get.hpp header file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2013-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_VARIANT_POLYMORPHIC_GET_HPP
#define BOOST_VARIANT_POLYMORPHIC_GET_HPP
#include <exception>
#include <boost/config.hpp>
#include <boost/core/addressof.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/static_assert.hpp>
#include <boost/throw_exception.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/variant/get.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/add_pointer.hpp>
#include <boost/type_traits/is_base_of.hpp>
#include <boost/type_traits/is_const.hpp>
namespace boost {
//////////////////////////////////////////////////////////////////////////
// class bad_polymorphic_get
//
// The exception thrown in the event of a failed get of a value.
//
class BOOST_SYMBOL_VISIBLE bad_polymorphic_get
: public bad_get
{
public: // std::exception implementation
virtual const char * what() const BOOST_NOEXCEPT_OR_NOTHROW
{
return "boost::bad_polymorphic_get: "
"failed value get using boost::polymorphic_get";
}
};
//////////////////////////////////////////////////////////////////////////
// function template get<T>
//
// Retrieves content of given variant object if content is of type T.
// Otherwise: pointer ver. returns 0; reference ver. throws bad_get.
//
namespace detail { namespace variant {
///////////////////////////////////////////////////////////////////////////////////////////////////
// polymorphic metafunctions to detect index of a value
//
template <class Types, class T>
struct element_polymorphic_iterator_impl :
boost::mpl::find_if<
Types,
boost::mpl::or_<
variant_element_functor<boost::mpl::_1, T>,
variant_element_functor<boost::mpl::_1, typename boost::remove_cv<T>::type >,
boost::is_base_of<T, boost::mpl::_1>
>
>
{};
template <class Variant, class T>
struct holds_element_polymorphic :
boost::mpl::not_<
boost::is_same<
typename boost::mpl::end<typename Variant::types>::type,
typename element_polymorphic_iterator_impl<typename Variant::types, typename boost::remove_reference<T>::type >::type
>
>
{};
// (detail) class template get_polymorphic_visitor
//
// Generic static visitor that: if the value is of the specified
// type or of a type derived from specified, returns a pointer
// to the value it visits; else a null pointer.
//
template <typename Base>
struct get_polymorphic_visitor
{
private: // private typedefs
typedef get_polymorphic_visitor<Base> this_type;
typedef typename add_pointer<Base>::type pointer;
typedef typename add_reference<Base>::type reference;
pointer get(reference operand, boost::true_type) const BOOST_NOEXCEPT
{
return boost::addressof(operand);
}
template <class T>
pointer get(T&, boost::false_type) const BOOST_NOEXCEPT
{
return static_cast<pointer>(0);
}
public: // visitor interfaces
typedef pointer result_type;
template <typename U>
pointer operator()(U& operand) const BOOST_NOEXCEPT
{
typedef typename boost::remove_reference<Base>::type base_t;
typedef boost::integral_constant<
bool,
(
boost::is_base_of<base_t, U>::value &&
(boost::is_const<base_t>::value || !boost::is_const<U>::value)
)
|| boost::is_same<base_t, U>::value
|| boost::is_same<typename boost::remove_cv<base_t>::type, U >::value
> tag_t;
return this_type::get(operand, tag_t());
}
};
}} // namespace detail::variant
#ifndef BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE
# if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x0551))
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t)
# else
# if defined(BOOST_NO_CXX11_NULLPTR)
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t) \
, t* = 0
# else
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t) \
, t* = nullptr
# endif
# endif
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// polymorphic_relaxed_get
//
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<U>::type
polymorphic_relaxed_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
{
typedef typename add_pointer<U>::type U_ptr;
if (!operand) return static_cast<U_ptr>(0);
detail::variant::get_polymorphic_visitor<U> v;
return operand->apply_visitor(v);
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<const U>::type
polymorphic_relaxed_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
{
typedef typename add_pointer<const U>::type U_ptr;
if (!operand) return static_cast<U_ptr>(0);
detail::variant::get_polymorphic_visitor<const U> v;
return operand->apply_visitor(v);
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<U>::type
polymorphic_relaxed_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
typedef typename add_pointer<U>::type U_ptr;
U_ptr result = polymorphic_relaxed_get<U>(&operand);
if (!result)
boost::throw_exception(bad_polymorphic_get());
return *result;
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<const U>::type
polymorphic_relaxed_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
typedef typename add_pointer<const U>::type U_ptr;
U_ptr result = polymorphic_relaxed_get<const U>(&operand);
if (!result)
boost::throw_exception(bad_polymorphic_get());
return *result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// polymorphic_strict_get
//
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<U>::type
polymorphic_strict_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT_MSG(
(boost::detail::variant::holds_element_polymorphic<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >, U >::value),
"boost::variant does not contain specified type U, "
"call to boost::polymorphic_get<U>(boost::variant<T...>*) will always return NULL"
);
return polymorphic_relaxed_get<U>(operand);
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<const U>::type
polymorphic_strict_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT_MSG(
(boost::detail::variant::holds_element_polymorphic<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >, U >::value),
"boost::variant does not contain specified type U, "
"call to boost::polymorphic_get<U>(const boost::variant<T...>*) will always return NULL"
);
return polymorphic_relaxed_get<U>(operand);
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<U>::type
polymorphic_strict_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
BOOST_STATIC_ASSERT_MSG(
(boost::detail::variant::holds_element_polymorphic<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >, U >::value),
"boost::variant does not contain specified type U, "
"call to boost::polymorphic_get<U>(boost::variant<T...>&) will always throw boost::bad_polymorphic_get exception"
);
return polymorphic_relaxed_get<U>(operand);
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<const U>::type
polymorphic_strict_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
BOOST_STATIC_ASSERT_MSG(
(boost::detail::variant::holds_element_polymorphic<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >, U >::value),
"boost::variant does not contain specified type U, "
"call to boost::polymorphic_get<U>(const boost::variant<T...>&) will always throw boost::bad_polymorphic_get exception"
);
return polymorphic_relaxed_get<U>(operand);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// polymorphic_get<U>(variant) methods
//
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<U>::type
polymorphic_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
{
#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
return polymorphic_relaxed_get<U>(operand);
#else
return polymorphic_strict_get<U>(operand);
#endif
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<const U>::type
polymorphic_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
{
#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
return polymorphic_relaxed_get<U>(operand);
#else
return polymorphic_strict_get<U>(operand);
#endif
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<U>::type
polymorphic_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
return polymorphic_relaxed_get<U>(operand);
#else
return polymorphic_strict_get<U>(operand);
#endif
}
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<const U>::type
polymorphic_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
return polymorphic_relaxed_get<U>(operand);
#else
return polymorphic_strict_get<U>(operand);
#endif
}
} // namespace boost
#endif // BOOST_VARIANT_POLYMORPHIC_GET_HPP
+33 -54
View File
@@ -3,8 +3,8 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2003
// Eric Friedman
// Copyright (c) 2003 Eric Friedman
// Copyright (c) 2013-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -13,27 +13,27 @@
#ifndef BOOST_VARIANT_RECURSIVE_VARIANT_HPP
#define BOOST_VARIANT_RECURSIVE_VARIANT_HPP
#include "boost/variant/variant_fwd.hpp"
#include "boost/variant/detail/enable_recursive.hpp"
#include "boost/variant/detail/substitute_fwd.hpp"
#include "boost/variant/detail/make_variant_list.hpp"
#include "boost/variant/detail/over_sequence.hpp"
#include <boost/variant/variant_fwd.hpp>
#include <boost/variant/detail/enable_recursive.hpp>
#include <boost/variant/detail/substitute_fwd.hpp>
#include <boost/variant/detail/make_variant_list.hpp>
#include <boost/variant/detail/over_sequence.hpp>
#include "boost/mpl/aux_/lambda_arity_param.hpp"
#include <boost/mpl/aux_/lambda_arity_param.hpp>
#include "boost/mpl/equal.hpp"
#include "boost/mpl/eval_if.hpp"
#include "boost/mpl/identity.hpp"
#include "boost/mpl/if.hpp"
#include "boost/mpl/protect.hpp"
#include "boost/mpl/transform.hpp"
#include "boost/type_traits/is_same.hpp"
#include "boost/preprocessor/cat.hpp"
#include "boost/preprocessor/repeat.hpp"
#include <boost/mpl/equal.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/protect.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/repeat.hpp>
#include "boost/mpl/bool.hpp"
#include "boost/mpl/is_sequence.hpp"
#include "boost/variant/variant.hpp"
#include <boost/mpl/bool.hpp>
#include <boost/mpl/is_sequence.hpp>
#include <boost/variant/variant.hpp>
namespace boost {
@@ -45,8 +45,6 @@ namespace detail { namespace variant {
// Handles embedded variant types when substituting for recursive_variant_.
//
#if !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
template <
BOOST_VARIANT_ENUM_PARAMS(typename T)
, typename RecursiveVariant
@@ -115,38 +113,21 @@ struct substitute<
, ::boost::recursive_variant_
BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(Arity)
>
{
private: // helpers, for metafunction result (below)
#define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS(z,N,_) \
typedef typename enable_recursive< \
BOOST_PP_CAT(T,N) \
, RecursiveVariant \
, mpl::true_ \
>::type BOOST_PP_CAT(wknd_T,N); \
/**/
BOOST_PP_REPEAT(
BOOST_VARIANT_LIMIT_TYPES
, BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS
, _
)
#undef BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS
public: // metafunction result
typedef ::boost::variant< BOOST_VARIANT_ENUM_PARAMS(wknd_T) > type;
{
typedef ::boost::variant<
typename enable_recursive<
T0
, RecursiveVariant
, mpl::true_
>::type,
typename enable_recursive<
TN
, RecursiveVariant
, mpl::true_
>::type...
> type;
};
#else // defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
//
// no specializations: embedded variants unsupported on these compilers!
//
#endif // !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
}} // namespace detail::variant
///////////////////////////////////////////////////////////////////////////////
@@ -176,9 +157,7 @@ struct make_recursive_variant_over
{
private: // precondition assertions
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
BOOST_STATIC_ASSERT(( ::boost::mpl::is_sequence<Types>::value ));
#endif
public: // metafunction result
+3 -3
View File
@@ -13,9 +13,9 @@
#ifndef BOOST_VARIANT_RECURSIVE_WRAPPER_HPP
#define BOOST_VARIANT_RECURSIVE_WRAPPER_HPP
#include "boost/variant/recursive_wrapper_fwd.hpp"
#include "boost/variant/detail/move.hpp"
#include "boost/checked_delete.hpp"
#include <boost/variant/recursive_wrapper_fwd.hpp>
#include <boost/variant/detail/move.hpp>
#include <boost/core/checked_delete.hpp>
namespace boost {
+43 -60
View File
@@ -3,8 +3,8 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2002
// Eric Friedman, Itay Maman
// Copyright (c) 2002 Eric Friedman, Itay Maman
// Copyright (c) 2016-2026 Antony Polukhin
//
// Portions Copyright (C) 2002 David Abrahams
//
@@ -15,18 +15,12 @@
#ifndef BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP
#define BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP
#include "boost/mpl/aux_/config/ctps.hpp"
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
# include "boost/mpl/eval_if.hpp"
# include "boost/mpl/bool.hpp"
# include "boost/mpl/identity.hpp"
# include "boost/type.hpp"
#endif
#include "boost/mpl/aux_/lambda_support.hpp"
// should be the last #include
#include "boost/type_traits/detail/bool_trait_def.hpp"
#include <boost/mpl/bool.hpp>
#include <boost/mpl/aux_/config/ctps.hpp>
#include <boost/mpl/aux_/lambda_support.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/is_constructible.hpp>
#include <boost/type_traits/is_nothrow_move_constructible.hpp>
namespace boost {
@@ -48,15 +42,42 @@ namespace boost {
//
template <typename T> class recursive_wrapper;
///////////////////////////////////////////////////////////////////////////////
// metafunction is_constructible partial specializations.
//
// recursive_wrapper<T> is constructible only from T and recursive_wrapper<T>.
//
template <class T> struct is_constructible<recursive_wrapper<T>, T> : boost::true_type{};
template <class T> struct is_constructible<recursive_wrapper<T>, const T> : boost::true_type{};
template <class T> struct is_constructible<recursive_wrapper<T>, T&> : boost::true_type{};
template <class T> struct is_constructible<recursive_wrapper<T>, const T&> : boost::true_type{};
template <class T> struct is_constructible<recursive_wrapper<T>, recursive_wrapper<T> > : boost::true_type{};
template <class T> struct is_constructible<recursive_wrapper<T>, const recursive_wrapper<T> > : boost::true_type{};
template <class T> struct is_constructible<recursive_wrapper<T>, recursive_wrapper<T>& > : boost::true_type{};
template <class T> struct is_constructible<recursive_wrapper<T>, const recursive_wrapper<T>& > : boost::true_type{};
template <class T, class U> struct is_constructible<recursive_wrapper<T>, U > : boost::false_type{};
template <class T, class U> struct is_constructible<recursive_wrapper<T>, const U > : boost::false_type{};
template <class T, class U> struct is_constructible<recursive_wrapper<T>, U& > : boost::false_type{};
template <class T, class U> struct is_constructible<recursive_wrapper<T>, const U& > : boost::false_type{};
template <class T, class U> struct is_constructible<recursive_wrapper<T>, recursive_wrapper<U> > : boost::false_type{};
template <class T, class U> struct is_constructible<recursive_wrapper<T>, const recursive_wrapper<U> > : boost::false_type{};
template <class T, class U> struct is_constructible<recursive_wrapper<T>, recursive_wrapper<U>& > : boost::false_type{};
template <class T, class U> struct is_constructible<recursive_wrapper<T>, const recursive_wrapper<U>& > : boost::false_type{};
// recursive_wrapper is not nothrow move constructible, because it's constructor does dynamic memory allocation.
// This specialisation is required to workaround GCC6 issue: https://svn.boost.org/trac/boost/ticket/12680
template <class T> struct is_nothrow_move_constructible<recursive_wrapper<T> > : boost::false_type{};
///////////////////////////////////////////////////////////////////////////////
// metafunction is_recursive_wrapper (modeled on code by David Abrahams)
//
// True iff specified type matches recursive_wrapper<T>.
// True if specified type matches recursive_wrapper<T>.
//
namespace detail {
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename T>
struct is_recursive_wrapper_impl
@@ -70,36 +91,15 @@ struct is_recursive_wrapper_impl< recursive_wrapper<T> >
{
};
#else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
typedef char (&yes_recursive_wrapper_t)[1];
typedef char (&no_recursive_wrapper_t)[2];
no_recursive_wrapper_t is_recursive_wrapper_test(...);
template<typename T>
yes_recursive_wrapper_t is_recursive_wrapper_test(
type< ::boost::recursive_wrapper<T> >
);
template<typename T>
struct is_recursive_wrapper_impl
{
BOOST_STATIC_CONSTANT(bool, value = (
sizeof(is_recursive_wrapper_test(type<T>()))
== sizeof(yes_recursive_wrapper_t)
));
};
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
} // namespace detail
BOOST_TT_AUX_BOOL_TRAIT_DEF1(
is_recursive_wrapper
, T
, (::boost::detail::is_recursive_wrapper_impl<T>::value)
)
template< typename T > struct is_recursive_wrapper
: public ::boost::integral_constant<bool,(::boost::detail::is_recursive_wrapper_impl<T>::value)>
{
public:
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_recursive_wrapper,(T))
};
///////////////////////////////////////////////////////////////////////////////
// metafunction unwrap_recursive
@@ -107,7 +107,6 @@ BOOST_TT_AUX_BOOL_TRAIT_DEF1(
// If specified type T matches recursive_wrapper<U>, then U; else T.
//
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename T>
struct unwrap_recursive
@@ -125,23 +124,7 @@ struct unwrap_recursive< recursive_wrapper<T> >
BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(1,unwrap_recursive,(T))
};
#else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <typename T>
struct unwrap_recursive
: mpl::eval_if<
is_recursive_wrapper<T>
, T
, mpl::identity< T >
>
{
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,unwrap_recursive,(T))
};
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
} // namespace boost
#include "boost/type_traits/detail/bool_trait_undef.hpp"
#endif // BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP
+17 -21
View File
@@ -13,18 +13,14 @@
#ifndef BOOST_VARIANT_STATIC_VISITOR_HPP
#define BOOST_VARIANT_STATIC_VISITOR_HPP
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include "boost/mpl/if.hpp"
#include "boost/type_traits/is_base_and_derived.hpp"
#include <boost/mpl/if.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
# include "boost/type_traits/is_same.hpp"
#endif
// should be the last #include
#include "boost/type_traits/detail/bool_trait_def.hpp"
#include <boost/type_traits/integral_constant.hpp>
#include <boost/mpl/aux_/lambda_support.hpp>
namespace boost {
@@ -52,10 +48,11 @@ public: // typedefs
typedef R result_type;
protected: // for use as base class only
static_visitor() { }
~static_visitor() { }
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && !defined(BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS)
static_visitor() = default;
#else
static_visitor() BOOST_NOEXCEPT { }
#endif
};
//////////////////////////////////////////////////////////////////////////
@@ -84,14 +81,13 @@ struct is_static_visitor_impl
} // namespace detail
BOOST_TT_AUX_BOOL_TRAIT_DEF1(
is_static_visitor
, T
, (::boost::detail::is_static_visitor_impl<T>::value)
)
template< typename T > struct is_static_visitor
: public ::boost::integral_constant<bool,(::boost::detail::is_static_visitor_impl<T>::value)>
{
public:
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_static_visitor,(T))
};
} // namespace boost
#include "boost/type_traits/detail/bool_trait_undef.hpp"
#endif // BOOST_VARIANT_STATIC_VISITOR_HPP
File diff suppressed because it is too large Load Diff
+49 -132
View File
@@ -3,8 +3,8 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2003
// Eric Friedman, Itay Maman
// Copyright (c) 2003 Eric Friedman, Itay Maman
// Copyright (c) 2013-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -13,47 +13,17 @@
#ifndef BOOST_VARIANT_VARIANT_FWD_HPP
#define BOOST_VARIANT_VARIANT_FWD_HPP
#include "boost/variant/detail/config.hpp"
#include <boost/variant/detail/config.hpp>
#include "boost/blank_fwd.hpp"
#include "boost/mpl/arg.hpp"
#include "boost/mpl/limits/arity.hpp"
#include "boost/mpl/aux_/na.hpp"
#include "boost/preprocessor/cat.hpp"
#include "boost/preprocessor/enum.hpp"
#include "boost/preprocessor/enum_params.hpp"
#include "boost/preprocessor/enum_shifted_params.hpp"
#include "boost/preprocessor/repeat.hpp"
///////////////////////////////////////////////////////////////////////////////
// macro BOOST_VARIANT_LIMIT_TYPES
//
// Implementation-defined preprocessor symbol describing the actual
// length of variant's pseudo-variadic template parameter list.
//
#include "boost/mpl/limits/list.hpp"
#define BOOST_VARIANT_LIMIT_TYPES \
BOOST_MPL_LIMIT_LIST_SIZE
///////////////////////////////////////////////////////////////////////////////
// macro BOOST_VARIANT_NO_REFERENCE_SUPPORT
//
// Defined if variant does not support references as bounded types.
//
#if defined(BOOST_VARIANT_AUX_BROKEN_CONSTRUCTOR_TEMPLATE_ORDERING) \
&& !defined(BOOST_VARIANT_AUX_HAS_CONSTRUCTOR_TEMPLATE_ORDERING_SFINAE_WKND) \
&& !defined(BOOST_VARIANT_NO_REFERENCE_SUPPORT)
# define BOOST_VARIANT_NO_REFERENCE_SUPPORT
#endif
///////////////////////////////////////////////////////////////////////////////
// macro BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT
//
// Defined if variant does not support make_variant_over (see below).
//
#if defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
# define BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT
#endif
#include <boost/blank_fwd.hpp>
#include <boost/mpl/arg.hpp>
#include <boost/mpl/limits/arity.hpp>
#include <boost/mpl/aux_/na.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/enum.hpp>
#include <boost/preprocessor/enum_params.hpp>
#include <boost/preprocessor/enum_shifted_params.hpp>
#include <boost/preprocessor/repeat.hpp>
///////////////////////////////////////////////////////////////////////////////
// macro BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT
@@ -64,41 +34,49 @@
// so only types declared w/ MPL lambda workarounds will work.
//
#include "boost/variant/detail/substitute_fwd.hpp"
#include <boost/variant/detail/substitute_fwd.hpp>
#if defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE) \
&& !defined(BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT)
# define BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT
#endif
#include <boost/preprocessor/seq/size.hpp>
#define BOOST_VARIANT_CLASS_OR_TYPENAME_TO_SEQ_class class)(
#define BOOST_VARIANT_CLASS_OR_TYPENAME_TO_SEQ_typename typename)(
#define BOOST_VARIANT_CLASS_OR_TYPENAME_TO_VARIADIC_class class...
#define BOOST_VARIANT_CLASS_OR_TYPENAME_TO_VARIADIC_typename typename...
#define ARGS_VARIADER_1(x) x ## N...
#define ARGS_VARIADER_2(x) BOOST_VARIANT_CLASS_OR_TYPENAME_TO_VARIADIC_ ## x ## N
#define BOOST_VARIANT_MAKE_VARIADIC(sequence, x) BOOST_VARIANT_MAKE_VARIADIC_I(BOOST_PP_SEQ_SIZE(sequence), x)
#define BOOST_VARIANT_MAKE_VARIADIC_I(argscount, x) BOOST_VARIANT_MAKE_VARIADIC_II(argscount, x)
#define BOOST_VARIANT_MAKE_VARIADIC_II(argscount, orig) ARGS_VARIADER_ ## argscount(orig)
///////////////////////////////////////////////////////////////////////////////
// macro BOOST_VARIANT_RECURSIVE_VARIANT_MAX_ARITY
// BOOST_VARIANT_ENUM_PARAMS and BOOST_VARIANT_ENUM_SHIFTED_PARAMS
//
// Exposes maximum allowed arity of class templates with recursive_variant
// arguments. That is,
// make_recursive_variant< ..., T<[1], recursive_variant_, ... [N]> >.
// Convenience macro for enumeration of variant params.
// When variadic templates are available expands:
// BOOST_VARIANT_ENUM_PARAMS(class Something) => class Something0, class... SomethingN
// BOOST_VARIANT_ENUM_PARAMS(typename Something) => typename Something0, typename... SomethingN
// BOOST_VARIANT_ENUM_PARAMS(Something) => Something0, SomethingN...
// BOOST_VARIANT_ENUM_PARAMS(Something) => Something0, SomethingN...
// BOOST_VARIANT_ENUM_SHIFTED_PARAMS(class Something) => class... SomethingN
// BOOST_VARIANT_ENUM_SHIFTED_PARAMS(typename Something) => typename... SomethingN
// BOOST_VARIANT_ENUM_SHIFTED_PARAMS(Something) => SomethingN...
// BOOST_VARIANT_ENUM_SHIFTED_PARAMS(Something) => SomethingN...
//
// Rationale: Cleaner, simpler code for clients of variant library. Minimal
// code modifications to move from C++03 to C++11.
//
#include "boost/mpl/limits/arity.hpp"
#define BOOST_VARIANT_RECURSIVE_VARIANT_MAX_ARITY \
BOOST_MPL_LIMIT_METAFUNCTION_ARITY
///////////////////////////////////////////////////////////////////////////////
// macro BOOST_VARIANT_ENUM_PARAMS
//
// Convenience macro for enumeration of BOOST_VARIANT_LIMIT_TYPES params.
//
// Rationale: Cleaner, simpler code for clients of variant library.
//
#define BOOST_VARIANT_ENUM_PARAMS( param ) \
BOOST_PP_ENUM_PARAMS(BOOST_VARIANT_LIMIT_TYPES, param)
#define BOOST_VARIANT_ENUM_PARAMS(x) \
x ## 0, \
BOOST_VARIANT_MAKE_VARIADIC( (BOOST_VARIANT_CLASS_OR_TYPENAME_TO_SEQ_ ## x), x) \
/**/
///////////////////////////////////////////////////////////////////////////////
// macro BOOST_VARIANT_ENUM_SHIFTED_PARAMS
//
// Convenience macro for enumeration of BOOST_VARIANT_LIMIT_TYPES-1 params.
//
#define BOOST_VARIANT_ENUM_SHIFTED_PARAMS( param ) \
BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_VARIANT_LIMIT_TYPES, param)
#define BOOST_VARIANT_ENUM_SHIFTED_PARAMS(x) \
BOOST_VARIANT_MAKE_VARIADIC( (BOOST_VARIANT_CLASS_OR_TYPENAME_TO_SEQ_ ## x), x) \
/**/
namespace boost {
@@ -131,70 +109,9 @@ struct convert_void< void_ >
typedef mpl::na type;
};
///////////////////////////////////////////////////////////////////////////////
// (workaround) BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE
//
// Needed to work around compilers that don't support using-declaration
// overloads. (See the variant::initializer workarounds below.)
//
#if defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
// (detail) tags voidNN -- NN defined on [0, BOOST_VARIANT_LIMIT_TYPES)
//
// Defines void types that are each unique and specializations of
// convert_void that yields mpl::na for each voidNN type.
//
#define BOOST_VARIANT_DETAIL_DEFINE_VOID_N(z,N,_) \
struct BOOST_PP_CAT(void,N); \
\
template <> \
struct convert_void< BOOST_PP_CAT(void,N) > \
{ \
typedef mpl::na type; \
}; \
/**/
BOOST_PP_REPEAT(
BOOST_VARIANT_LIMIT_TYPES
, BOOST_VARIANT_DETAIL_DEFINE_VOID_N
, _
)
#undef BOOST_VARIANT_DETAIL_DEFINE_VOID_N
#endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
}} // namespace detail::variant
///////////////////////////////////////////////////////////////////////////////
// (detail) macro BOOST_VARIANT_AUX_DECLARE_PARAM
//
// Template parameter list for variant and recursive_variant declarations.
//
#if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
# define BOOST_VARIANT_AUX_DECLARE_PARAMS_IMPL(z, N, T) \
typename BOOST_PP_CAT(T,N) = detail::variant::void_ \
/**/
#else // defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
# define BOOST_VARIANT_AUX_DECLARE_PARAMS_IMPL(z, N, T) \
typename BOOST_PP_CAT(T,N) = BOOST_PP_CAT(detail::variant::void,N) \
/**/
#endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
#define BOOST_VARIANT_AUX_DECLARE_PARAMS \
BOOST_PP_ENUM( \
BOOST_VARIANT_LIMIT_TYPES \
, BOOST_VARIANT_AUX_DECLARE_PARAMS_IMPL \
, T \
) \
/**/
#define BOOST_VARIANT_AUX_DECLARE_PARAMS BOOST_VARIANT_ENUM_PARAMS(typename T)
///////////////////////////////////////////////////////////////////////////////
// class template variant (concept inspired by Andrei Alexandrescu)
+9 -38
View File
@@ -13,15 +13,15 @@
#ifndef BOOST_VARIANT_VISITOR_PTR_HPP
#define BOOST_VARIANT_VISITOR_PTR_HPP
#include "boost/variant/bad_visit.hpp"
#include "boost/variant/static_visitor.hpp"
#include <boost/variant/bad_visit.hpp>
#include <boost/variant/static_visitor.hpp>
#include "boost/mpl/eval_if.hpp"
#include "boost/mpl/identity.hpp"
#include "boost/throw_exception.hpp"
#include "boost/type_traits/add_reference.hpp"
#include "boost/type_traits/is_reference.hpp"
#include "boost/type_traits/is_void.hpp"
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/throw_exception.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/is_void.hpp>
namespace boost {
@@ -55,7 +55,7 @@ private: // private typedefs
public: // structors
explicit visitor_ptr_t(visitor_t visitor)
explicit visitor_ptr_t(visitor_t visitor) BOOST_NOEXCEPT
: visitor_(visitor)
{
}
@@ -68,8 +68,6 @@ public: // static visitor interfaces
boost::throw_exception(bad_visit());
}
#if !defined(BOOST_NO_VOID_RETURNS)
public: // static visitor interfaces, cont.
result_type operator()(argument_fwd_type operand) const
@@ -77,33 +75,6 @@ public: // static visitor interfaces, cont.
return visitor_(operand);
}
#else // defined(BOOST_NO_VOID_RETURNS)
private: // helpers, for static visitor interfaces (below)
result_type execute_impl(argument_fwd_type operand, mpl::false_) const
{
return visitor_(operand);
}
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
execute_impl(argument_fwd_type operand, mpl::true_) const
{
visitor_(operand);
BOOST_VARIANT_AUX_RETURN_VOID;
}
public: // static visitor interfaces, cont.
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
operator()(argument_fwd_type operand) const
{
typedef typename is_void<result_type>::type has_void_result;
return execute_impl(operand, has_void_result());
}
#endif // BOOST_NO_VOID_RETURNS workaround
};
template <typename R, typename T>
+28 -2
View File
@@ -1,9 +1,35 @@
<!DOCTYPE html>
<!--
Copyright 2014-2026 Antony Polukhin
antoshkka at gmail dot com
Distributed under the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt
or copy at http://boost.org/LICENSE_1_0.txt)
-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; URL=../../doc/html/variant.html">
<title>Boost.Variant</title>
<style>
body {
background: #fff;
color: #000;
}
a {
color: #00f;
text-decoration: none;
}
</style>
</head>
<body>
Automatic redirection failed, please go to
<a href="../../doc/html/variant.html">../../doc/html/variant.html</a>
<p>
Automatic redirection failed, please go to
<a href="../../doc/html/variant.html">../../doc/html/variant.html</a>
</p>
<p>
&copy; 2014-2024 Antony Polukhin
</p>
</body>
</html>
+18
View File
@@ -0,0 +1,18 @@
{
"key": "variant",
"name": "Variant",
"authors": [
"Eric Friedman",
"Itay Maman"
],
"description": "Safe, generic, stack-based discriminated union container.",
"category": [
"Containers",
"Data"
],
"maintainers": [
"Antony Polukhin <antoshkka -at- gmail.com>",
"Eric Friedman <ericbrandon -at- gmail.com>"
],
"cxxstd": "11"
}
+1 -1
View File
@@ -1,5 +1,5 @@
#==============================================================================
# Copyright (c) 2012 Antony Polukhin
# Copyright (c) 2012-2026 Antony Polukhin
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Executable → Regular
+13 -6
View File
@@ -1,4 +1,4 @@
// (C) Copyright Antony Polukhin 2012.
// (C) Copyright Antony Polukhin 2012-2021.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -75,7 +75,7 @@ static void do_test(bool do_count_cleanup_time = false) {
{
scope sc("boost::variant(variant&&) moving speed");
for (std::size_t i = 0; i < c_run_count; ++i) {
data_to.push_back(std::move(data_from[i]));
data_to.push_back(boost::move(data_from[i]));
}
if (do_count_cleanup_time) {
@@ -108,7 +108,7 @@ static void do_test(bool do_count_cleanup_time = false) {
{
scope sc("boost::variant=(variant&&) moving speed on same types");
for (std::size_t i = 0; i < c_run_count; ++i) {
data_to[i] = std::move(data_from[i]);
data_to[i] = boost::move(data_from[i]);
}
if (do_count_cleanup_time) {
@@ -142,7 +142,7 @@ static void do_test(bool do_count_cleanup_time = false) {
{
scope sc("boost::variant=(variant&&) moving speed on different types");
for (std::size_t i = 0; i < c_run_count; ++i) {
data_to[i] = std::move(data_from[i]);
data_to[i] = boost::move(data_from[i]);
}
if (do_count_cleanup_time) {
@@ -176,7 +176,7 @@ static void do_test(bool do_count_cleanup_time = false) {
{
scope sc("boost::variant=(variant&&) moving speed on different types II");
for (std::size_t i = 0; i < c_run_count; ++i) {
data_to[i] = std::move(data_from[i]);
data_to[i] = boost::move(data_from[i]);
}
if (do_count_cleanup_time) {
@@ -210,7 +210,7 @@ static void do_test(bool do_count_cleanup_time = false) {
{
scope sc("boost::variant=(T&&) moving speed");
for (std::size_t i = 0; i < c_run_count; ++i) {
data_to[i] = std::move(s2[i]);
data_to[i] = boost::move(s2[i]);
}
if (do_count_cleanup_time) {
@@ -222,6 +222,13 @@ static void do_test(bool do_count_cleanup_time = false) {
int main () {
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
std::cout << "# Running tests in C++11 mode (with rvalues).\n";
#else
std::cout << "# Running tests in C++03 mode (without rvalues).\n";
#endif
do_test(false);
do_test(true);
}
+37 -15
View File
@@ -1,41 +1,53 @@
# Boost.Variant Library test Jamfile
#
# Copyright (C) 2003, Eric Friedman, Itay Maman.
# Copyright (C) 2013, Antony Polukhin.
# Copyright (C) 2013-2026 Antony Polukhin.
#
# This material is provided "as is", with absolutely no warranty expressed
# or implied. Any use is at your own risk.
#
# Permission to use or copy this software for any purpose is hereby granted
# without fee, provided the above notices are retained on all copies.
# Permission to modify the code and to distribute modified code is granted,
# provided the above notices are retained, and a notice that the code was
# modified is included with the above copyright notice.
# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
require-b2 5.0.1 ;
import-search /boost/config/checks ;
import config : requires ;
import testing ;
local below_cpp14 = 98 03 0x 11 ;
local since_cpp20 = 2a 20 latest ;
project
: requirements
#<dependency>/boost/test//minimal
<library>/boost/variant//boost_variant
[ requires cxx11_rvalue_references ]
<toolset>msvc:<asynch-exceptions>on
;
test-suite variant
:
:
[ run test1.cpp class_a.cpp : : : : variant_test1 ]
[ run test2.cpp : : : : variant_test2 ]
[ run test3.cpp : : : : variant_test3 ]
[ run test4.cpp class_a.cpp
: : : : variant_test4 ]
[ run test3.cpp : : : <rtti>off <define>BOOST_NO_RTTI <define>BOOST_NO_TYPEID : variant_test3_no_rtti ]
[ run test4.cpp class_a.cpp : : : : variant_test4 ]
[ run test5.cpp : : : : variant_test5 ]
[ run test6.cpp : : : : variant_test6 ]
[ run test7.cpp : : : : variant_test7 ]
[ run test8.cpp : : : : variant_test8 ]
[ run test9.cpp : : : <library>/boost/fusion//boost_fusion : variant_test9 ]
[ run recursive_variant_test.cpp ]
[ run variant_reference_test.cpp ]
[ run variant_comparison_test.cpp ]
[ run variant_visit_internal_linkage.cpp : : : "<cxxstd>$(below_cpp14)"\:<build>no ]
[ run variant_visit_test.cpp ]
[ run variant_get_test.cpp ]
[ compile-fail variant_rvalue_get_with_ampersand_test.cpp ]
[ compile-fail no_rvalue_to_nonconst_visitation.cpp ]
[ compile fusion_interop.cpp : <library>/boost/fusion//boost_fusion ]
[ run variant_polymorphic_get_test.cpp ]
[ run variant_multivisit_test.cpp ]
[ run hash_variant_test.cpp ]
[ run rvalue_test.cpp ]
[ run variant_nonempty_check.cpp ]
[ run recursive_variant_test.cpp : : : <define>BOOST_NO_EXCEPTIONS
<toolset>gcc-4.3:<cxxflags>-fno-exceptions
<toolset>gcc-4.4:<cxxflags>-fno-exceptions
@@ -46,6 +58,16 @@ test-suite variant
<toolset>clang:<cxxflags>-fno-exceptions
: variant_noexcept_test
]
;
[ run recursive_variant_test.cpp : : : <rtti>off <define>BOOST_NO_RTTI <define>BOOST_NO_TYPEID : variant_no_rtti_test ]
[ run hash_recursive_variant_test.cpp ]
[ run variant_swap_test.cpp ]
[ run auto_visitors.cpp : : : <library>/boost/lexical_cast//boost_lexical_cast ]
[ run issue42.cpp ]
[ compile issue53.cpp : <library>/boost/thread//boost_thread ]
[ run overload_selection.cpp : : : "<cxxstd>$(since_cpp20)"\:<build>no ]
[ run recursive_wrapper_move_test.cpp : : : <library>/boost/array//boost_array ]
[ run variant_over_joint_view_test.cpp ]
[ run const_ref_apply_visitor.cpp : : : <library>/boost/lexical_cast//boost_lexical_cast ]
;
+92
View File
@@ -0,0 +1,92 @@
# Use, modification, and distribution are
# subject to the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
# Copyright Antony Polukhin 2016-2021.
#
# See https://svn.boost.org/trac/boost/wiki/TravisCoverals for description of this file
# and how it can be used with Boost libraries.
#
# File revision #7
init:
# boost-local/libs/ folder to put this library into. This may be useful, if you're for example running Travis
# from `Boost.DLL` repo while Boost already has `dll` and with to replace `dll` with content of`Boost.DLL`.
#
# Otherwise just leave the default value - set BOOST_LIBS_FOLDER=%APPVEYOR_PROJECT_NAME%
- set BOOST_LIBS_FOLDER=%APPVEYOR_PROJECT_NAME%
###############################################################################################################
# From this point and below code is same for all the Boost libs
###############################################################################################################
version: 1.71.{build}-{branch}
# branches to build
branches:
except:
- gh-pages
skip_tags: true
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: msvc-14.1,clang-win
CXXSTD: 14,17
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
ADDPATH: C:\cygwin\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
ADDPATH: C:\cygwin64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
VARIANT: release # "variant_get_test.o: File too big" errors in debug
# MinGW 32-bit is not supported by Boost.System any more
# - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
# ADDPATH: C:\mingw\bin;
# TOOLSET: gcc
# CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
ADDPATH: C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
VARIANT: release # "variant_get_test.o: File too big" errors in debug
before_build:
- set BOOST_BRANCH=develop
- if "%APPVEYOR_REPO_BRANCH%" == "master" set BOOST_BRANCH=master
- echo "Testing %APPVEYOR_PROJECT_NAME%"
# Cloning Boost libraries (fast nondeep cloning)
- set BOOST=C:/boost-local
- git clone -b %BOOST_BRANCH% --depth 10 https://github.com/boostorg/boost.git %BOOST%
- cd %BOOST%
- git submodule update --init --depth 10 tools/build tools/boostdep
- rm -rf %BOOST%/libs/%BOOST_LIBS_FOLDER%
- mv -f %APPVEYOR_BUILD_FOLDER% %BOOST%/libs/%BOOST_LIBS_FOLDER%
- python tools/boostdep/depinst/depinst.py --git_args "--depth 10 --jobs 2" %BOOST_LIBS_FOLDER%
build_script:
- cmd /c bootstrap
- b2.exe headers
- cd %BOOST%/libs/%BOOST_LIBS_FOLDER%/test
after_build:
before_test:
test_script:
- PATH=%ADDPATH%%PATH%
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
- if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
- if "%VARIANT%"== "" set VARIANT=debug,release
- set VARIANT=variant=%VARIANT%
- echo "Running command ..\..\..\b2 -j3 toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release"
- ..\..\..\b2.exe -j3 toolset=%TOOLSET% %CXXSTD% %ADDRMD% %VARIANT% cxxflags="-DBOOST_TRAVISCI_BUILD"
after_test:
on_success:
on_failure:
on_finish:
+370
View File
@@ -0,0 +1,370 @@
//-----------------------------------------------------------------------------
// boost-libs variant/test/auto_visitors.cpp source file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2014-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "boost/config.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/variant.hpp"
#include "boost/variant/multivisitors.hpp"
#include "boost/lexical_cast.hpp"
#include <boost/noncopyable.hpp>
#include <boost/core/ignore_unused.hpp>
namespace has_result_type_tests {
template <class T>
struct wrap {
typedef T result_type;
};
struct s1 : wrap<int> {};
struct s2 : wrap<int&> {};
struct s3 : wrap<const int&> {};
struct s4 {};
struct s5 : wrap<int*> {};
struct s6 : wrap<int**> {};
struct s7 : wrap<const int*> {};
struct s8 : wrap<boost::noncopyable> {};
struct s9 : wrap<boost::noncopyable&> {};
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
struct s10 : wrap<boost::noncopyable&&> {};
#endif
struct s11 : wrap<const boost::noncopyable&> {};
struct s12 : wrap<const boost::noncopyable*> {};
struct s13 : wrap<boost::noncopyable*> {};
struct s14 { typedef int result_type; };
struct s15 { typedef int& result_type; };
struct s16 { typedef const int& result_type; };
}
void test_has_result_type_triat() {
using namespace has_result_type_tests;
using boost::detail::variant::has_result_type;
BOOST_TEST(has_result_type<s1>::value);
BOOST_TEST(has_result_type<s2>::value);
BOOST_TEST(has_result_type<s3>::value);
BOOST_TEST(!has_result_type<s4>::value);
BOOST_TEST(has_result_type<s5>::value);
BOOST_TEST(has_result_type<s6>::value);
BOOST_TEST(has_result_type<s7>::value);
BOOST_TEST(has_result_type<s8>::value);
BOOST_TEST(has_result_type<s9>::value);
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
BOOST_TEST(has_result_type<s10>::value);
#endif
BOOST_TEST(has_result_type<s11>::value);
BOOST_TEST(has_result_type<s12>::value);
BOOST_TEST(has_result_type<s13>::value);
BOOST_TEST(has_result_type<s14>::value);
BOOST_TEST(has_result_type<s15>::value);
BOOST_TEST(has_result_type<s16>::value);
}
struct lex_streamer_explicit: boost::static_visitor<std::string> {
template <class T>
const char* operator()(const T& ) {
return "10";
}
template <class T1, class T2>
const char* operator()(const T1& , const T2& ) {
return "100";
}
};
void run_explicit()
{
typedef boost::variant<int, std::string, double> variant_type;
variant_type v2("10"), v1("100");
lex_streamer_explicit visitor_ref;
// Must return instance of std::string
BOOST_TEST(boost::apply_visitor(visitor_ref, v2).c_str() == std::string("10"));
BOOST_TEST(boost::apply_visitor(visitor_ref, v2, v1).c_str() == std::string("100"));
}
// Most part of tests from this file require decltype(auto)
#ifdef BOOST_NO_CXX14_DECLTYPE_AUTO
void run()
{
BOOST_TEST(true);
}
void run2()
{
BOOST_TEST(true);
}
void run3()
{
BOOST_TEST(true);
}
#else
#include <iostream>
struct lex_streamer {
template <class T>
std::string operator()(const T& val) const {
return boost::lexical_cast<std::string>(val);
}
};
struct lex_streamer_void {
template <class T>
void operator()(const T& val) const {
std::cout << val << std::endl;
}
template <class T1, class T2>
void operator()(const T1& val, const T2& val2) const {
std::cout << val << '+' << val2 << std::endl;
}
template <class T1, class T2, class T3>
void operator()(const T1& val, const T2& val2, const T3& val3) const {
std::cout << val << '+' << val2 << '+' << val3 << std::endl;
}
};
struct lex_streamer2 {
std::string res;
template <class T>
const char* operator()(const T& /*val*/) const {
return "fail";
}
template <class T1, class T2>
const char* operator()(const T1& /*v1*/, const T2& /*v2*/) const {
return "fail2";
}
template <class T1, class T2, class T3>
const char* operator()(const T1& /*v1*/, const T2& /*v2*/, const T3& /*v3*/) const {
return "fail3";
}
template <class T>
std::string& operator()(const T& val) {
res = boost::lexical_cast<std::string>(val);
return res;
}
template <class T1, class T2>
std::string& operator()(const T1& v1, const T2& v2) {
res = boost::lexical_cast<std::string>(v1) + "+" + boost::lexical_cast<std::string>(v2);
return res;
}
template <class T1, class T2, class T3>
std::string& operator()(const T1& v1, const T2& v2, const T3& v3) {
res = boost::lexical_cast<std::string>(v1) + "+" + boost::lexical_cast<std::string>(v2)
+ "+" + boost::lexical_cast<std::string>(v3);
return res;
}
};
void run()
{
typedef boost::variant<int, std::string, double> variant_type;
variant_type v1(1), v2("10"), v3(100.0);
lex_streamer lex_streamer_visitor;
BOOST_TEST(boost::apply_visitor(lex_streamer(), v1) == "1");
BOOST_TEST(boost::apply_visitor(lex_streamer_visitor)(v1) == "1");
BOOST_TEST(boost::apply_visitor(lex_streamer(), v2) == "10");
BOOST_TEST(boost::apply_visitor(lex_streamer_visitor)(v2) == "10");
#ifndef BOOST_NO_CXX14_GENERIC_LAMBDAS
BOOST_TEST(boost::apply_visitor([](auto v) { return boost::lexical_cast<std::string>(v); }, v1) == "1");
BOOST_TEST(boost::apply_visitor([](auto v) { return boost::lexical_cast<std::string>(v); }, v2) == "10");
// Retun type must be the same in all instances, so this code does not compile
//boost::variant<int, short, unsigned> v_diff_types(1);
//BOOST_TEST(boost::apply_visitor([](auto v) { return v; }, v_diff_types) == 1);
boost::apply_visitor([](auto v) { std::cout << v << std::endl; }, v1);
boost::apply_visitor([](auto v) { std::cout << v << std::endl; }, v2);
#endif
lex_streamer2 visitor_ref;
BOOST_TEST(boost::apply_visitor(visitor_ref, v1) == "1");
BOOST_TEST(boost::apply_visitor(visitor_ref, v2) == "10");
std::string& ref_to_string = boost::apply_visitor(visitor_ref, v1);
BOOST_TEST(ref_to_string == "1");
lex_streamer_void lex_streamer_void_visitor;
boost::apply_visitor(lex_streamer_void(), v1);
boost::apply_visitor(lex_streamer_void(), v2);
boost::apply_visitor(lex_streamer_void_visitor)(v2);
boost::ignore_unused(lex_streamer_visitor, visitor_ref, lex_streamer_void_visitor);
}
struct lex_combine {
template <class T1, class T2>
std::string operator()(const T1& v1, const T2& v2) const {
return boost::lexical_cast<std::string>(v1) + "+" + boost::lexical_cast<std::string>(v2);
}
template <class T1, class T2, class T3>
std::string operator()(const T1& v1, const T2& v2, const T3& v3) const {
return boost::lexical_cast<std::string>(v1) + "+"
+ boost::lexical_cast<std::string>(v2) + '+'
+ boost::lexical_cast<std::string>(v3);
}
};
void run2()
{
typedef boost::variant<int, std::string, double> variant_type;
variant_type v1(1), v2("10"), v3(100.0);
lex_combine lex_combine_visitor;
BOOST_TEST(boost::apply_visitor(lex_combine(), v1, v2) == "1+10");
BOOST_TEST(boost::apply_visitor(lex_combine(), v2, v1) == "10+1");
BOOST_TEST(boost::apply_visitor(lex_combine_visitor)(v2, v1) == "10+1");
#ifndef BOOST_NO_CXX14_GENERIC_LAMBDAS
BOOST_TEST(
boost::apply_visitor(
[](auto v1, auto v2) {
return boost::lexical_cast<std::string>(v1) + "+"
+ boost::lexical_cast<std::string>(v2);
}
, v1
, v2
) == "1+10"
);
BOOST_TEST(
boost::apply_visitor(
[](auto v1, auto v2) {
return boost::lexical_cast<std::string>(v1) + "+"
+ boost::lexical_cast<std::string>(v2);
}
, v2
, v1
) == "10+1"
);
boost::apply_visitor([](auto v1, auto v2) { std::cout << v1 << '+' << v2 << std::endl; }, v1, v2);
boost::apply_visitor([](auto v1, auto v2) { std::cout << v1 << '+' << v2 << std::endl; }, v2, v1);
#endif
lex_streamer2 visitor_ref;
BOOST_TEST(boost::apply_visitor(visitor_ref, v1, v2) == "1+10");
BOOST_TEST(boost::apply_visitor(visitor_ref, v2, v1) == "10+1");
std::string& ref_to_string = boost::apply_visitor(visitor_ref)(v1, v2);
BOOST_TEST(ref_to_string == "1+10");
boost::apply_visitor(lex_streamer_void(), v1, v2);
boost::apply_visitor(lex_streamer_void(), v2, v1);
boost::ignore_unused(lex_combine_visitor, visitor_ref);
}
void run3()
{
typedef boost::variant<int, std::string, double> variant_type;
variant_type v1(1), v2("10"), v3(100);
lex_combine lex_combine_visitor;
BOOST_TEST(boost::apply_visitor(lex_combine(), v1, v2, v3) == "1+10+100");
BOOST_TEST(boost::apply_visitor(lex_combine(), v2, v1, v3) == "10+1+100");
BOOST_TEST(boost::apply_visitor(lex_combine_visitor)(v2, v1, v3) == "10+1+100");
#ifndef BOOST_NO_CXX14_GENERIC_LAMBDAS
BOOST_TEST(
boost::apply_visitor(
[](auto v1, auto v2, auto v3) {
return boost::lexical_cast<std::string>(v1) + "+"
+ boost::lexical_cast<std::string>(v2) + "+"
+ boost::lexical_cast<std::string>(v3);
}
, v1
, v2
, v3
) == "1+10+100"
);
BOOST_TEST(
boost::apply_visitor(
[](auto v1, auto v2, auto v3) {
return boost::lexical_cast<std::string>(v1) + "+"
+ boost::lexical_cast<std::string>(v2) + "+"
+ boost::lexical_cast<std::string>(v3);
}
, v3
, v1
, v3
) == "100+1+100"
);
boost::apply_visitor(
[](auto v1, auto v2, auto v3) { std::cout << v1 << '+' << v2 << '+' << v3 << std::endl; },
v1, v2, v3
);
boost::apply_visitor(
[](auto v1, auto v2, auto v3) { std::cout << v1 << '+' << v2 << '+' << v3 << std::endl; },
v2, v1, v3
);
#endif
lex_streamer2 visitor_ref;
BOOST_TEST(boost::apply_visitor(visitor_ref, v1, v2) == "1+10");
BOOST_TEST(boost::apply_visitor(visitor_ref)(v2, v1) == "10+1");
std::string& ref_to_string = boost::apply_visitor(visitor_ref, v1, v2);
BOOST_TEST(ref_to_string == "1+10");
lex_streamer_void lex_streamer_void_visitor;
boost::apply_visitor(lex_streamer_void(), v1, v2, v1);
boost::apply_visitor(lex_streamer_void(), v2, v1, v1);
boost::apply_visitor(lex_streamer_void_visitor)(v2, v1, v1);
}
#endif
int main()
{
run_explicit();
run();
run2();
run3();
test_has_result_type_triat();
return boost::report_errors();
}
+3 -2
View File
@@ -13,7 +13,8 @@
#include <algorithm> // for std::swap
#include <sstream>
#include <iostream>
#include <assert.h>
#include <boost/assert.hpp>
#include "class_a.h"
@@ -22,7 +23,7 @@ using namespace std;
class_a::~class_a()
{
assert(self_p_ == this);
BOOST_ASSERT(self_p_ == this);
}
class_a::class_a(int n)
+334
View File
@@ -0,0 +1,334 @@
// Copyright (c) 2017 Levon Tarakchyan
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "boost/config.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/variant.hpp"
#include "boost/variant/apply_visitor.hpp"
#include "boost/variant/multivisitors.hpp"
#include "boost/lexical_cast.hpp"
#define lcs(val) boost::lexical_cast<std::string>(val)
struct construction_logger
{
int val_;
construction_logger(int val) : val_(val)
{
std::cout << val_ << " constructed\n";
}
construction_logger(const construction_logger& cl) :
val_(cl.val_)
{
std::cout << val_ << " copy constructed\n";
}
construction_logger(construction_logger&& cl) :
val_(cl.val_)
{
std::cout << val_ << " move constructed\n";
}
friend std::ostream& operator << (std::ostream& os, const construction_logger& cl)
{
return os << cl.val_;
}
friend std::istream& operator << (std::istream& is, construction_logger& cl)
{
return is >> cl.val_;
}
};
struct lex_streamer_explicit : boost::static_visitor<std::string>
{
template <class T>
std::string operator()(const T& val) const
{
return lcs(val);
}
template <class T, class V>
std::string operator()(const T& val, const V& val2) const
{
return lcs(val) + '+' + lcs(val2);
}
template <class T, class V, class P, class S>
std::string operator()(const T& val, const V& val2, const P& val3, const S& val4) const
{
return lcs(val) + '+' + lcs(val2) + '+' + lcs(val3) + '+' + lcs(val4);
}
};
struct lvalue_rvalue_detector : boost::static_visitor<std::string>
{
template <class T>
std::string operator()(T&&) const
{
return std::is_lvalue_reference<T>::value ? "lvalue reference"
: "rvalue reference";
}
template <class T, class V>
std::string operator()(T&& t, V&& v) const
{
return operator()(std::forward<T>(t)) + ", " + operator()(std::forward<V>(v));
}
template <class T, class V, class P>
std::string operator()(T&& t, V&& v, P&& p) const
{
return operator()(std::forward<T>(t), std::forward<V>(v)) + ", " + operator()(std::forward<P>(p));
}
template <class T, class V, class P, class S>
std::string operator()(T&& t, V&& v, P&& p, S&& s) const
{
return operator()(std::forward<T>(t), std::forward<V>(v), std::forward<P>(p)) + ", " + operator()(std::forward<S>(s));
}
};
typedef boost::variant<construction_logger, std::string> variant_type;
void test_const_ref_parameter(const variant_type& test_var)
{
std::cout << "Testing const lvalue reference visitable\n";
BOOST_TEST(boost::apply_visitor(lvalue_rvalue_detector(), test_var) == "lvalue reference");
}
void test_const_ref_parameter2(const variant_type& test_var, const variant_type& test_var2)
{
std::cout << "Testing const lvalue reference visitable\n";
BOOST_TEST(boost::apply_visitor(lvalue_rvalue_detector(), test_var, test_var2) == "lvalue reference, lvalue reference");
}
void test_const_ref_parameter4(const variant_type& test_var, const variant_type& test_var2, const variant_type& test_var3, const variant_type& test_var4)
{
std::cout << "Testing const lvalue reference visitable with multivisitor\n";
BOOST_TEST(boost::apply_visitor(lvalue_rvalue_detector(), test_var, test_var2, test_var3, test_var4)
== "lvalue reference, lvalue reference, lvalue reference, lvalue reference");
}
void test_rvalue_parameter(variant_type&& test_var)
{
std::cout << "Testing rvalue visitable\n";
const auto expected_val = lcs(test_var);
BOOST_TEST(boost::apply_visitor(lvalue_rvalue_detector(), std::move(test_var)) == "rvalue reference");
}
void test_rvalue_parameter2(variant_type&& test_var, variant_type&& test_var2)
{
std::cout << "Testing rvalue visitable\n";
BOOST_TEST(boost::apply_visitor(lvalue_rvalue_detector(), std::move(test_var), std::move(test_var2)) == "rvalue reference, rvalue reference");
}
void test_rvalue_parameter4(variant_type&& test_var, variant_type&& test_var2, variant_type&& test_var3, variant_type&& test_var4)
{
std::cout << "Testing rvalue visitable with multivisitor\n";
auto result = boost::apply_visitor(lvalue_rvalue_detector(), std::move(test_var), std::move(test_var2), std::move(test_var3), std::move(test_var4));
std::cout << "result: " << result << std::endl;
BOOST_TEST(result == "rvalue reference, rvalue reference, rvalue reference, rvalue reference");
}
#ifndef BOOST_NO_CXX14_DECLTYPE_AUTO
#define FORWARD(x) std::forward<decltype(x)>(x)
void test_cpp14_visitor(const variant_type& test_var)
{
std::cout << "Testing const lvalue visitable for c++14\n";
BOOST_TEST(boost::apply_visitor([](auto&& v) { return lvalue_rvalue_detector()(FORWARD(v)); }, test_var) == "lvalue reference");
}
void test_cpp14_mutable_visitor(const variant_type& test_var)
{
std::cout << "Testing const lvalue visitable for c++14 with inline mutable lambda\n";
BOOST_TEST(boost::apply_visitor([](auto&& v) mutable -> auto { return lvalue_rvalue_detector()(FORWARD(v)); }, test_var) == "lvalue reference");
}
void test_cpp14_visitor(const variant_type& test_var, const variant_type& test_var2)
{
std::cout << "Testing const lvalue visitable for c++14\n";
BOOST_TEST(boost::apply_visitor([](auto&& v, auto&& vv) { return lvalue_rvalue_detector()(FORWARD(v), FORWARD(vv)); }, test_var, test_var2)
== "lvalue reference, lvalue reference");
}
void test_cpp14_visitor(const variant_type& test_var, const variant_type& test_var2, const variant_type& test_var3)
{
std::cout << "Testing const lvalue visitable for c++14\n";
auto result = boost::apply_visitor([](auto&& v, auto&& t, auto&& p) { return lvalue_rvalue_detector()(FORWARD(v), FORWARD(t), FORWARD(p)); },
test_var, test_var2, test_var3);
std::cout << "result: " << result << std::endl;
BOOST_TEST(result == "lvalue reference, lvalue reference, lvalue reference");
}
void test_cpp14_visitor(variant_type& test_var)
{
std::cout << "Testing lvalue visitable for c++14\n";
BOOST_TEST(boost::apply_visitor([](auto& v) { return lvalue_rvalue_detector()(v); }, test_var) == "lvalue reference");
}
void test_cpp14_mutable_visitor(variant_type& test_var)
{
std::cout << "Testing lvalue visitable for c++14 with inline mutable lambda\n";
BOOST_TEST(boost::apply_visitor([](auto& v) mutable -> auto { return lvalue_rvalue_detector()(v); }, test_var) == "lvalue reference");
}
void test_cpp14_visitor(variant_type& test_var, variant_type& test_var2)
{
std::cout << "Testing lvalue visitable for c++14\n";
BOOST_TEST(boost::apply_visitor([](auto& v, auto& vv) { return lvalue_rvalue_detector()(v, vv); }, test_var, test_var2)
== "lvalue reference, lvalue reference");
}
void test_cpp14_visitor(variant_type& test_var, variant_type& test_var2, variant_type& test_var3)
{
std::cout << "Testing lvalue visitable for c++14\n";
auto result = boost::apply_visitor([](auto& v, auto& t, auto& p) { return lvalue_rvalue_detector()(v, t, p); },
test_var, test_var2, test_var3);
std::cout << "result: " << result << std::endl;
BOOST_TEST(result == "lvalue reference, lvalue reference, lvalue reference");
}
void test_cpp14_visitor(variant_type&& test_var)
{
std::cout << "Testing rvalue visitable for c++14\n";
BOOST_TEST(boost::apply_visitor([](auto&& v) { return lvalue_rvalue_detector()(FORWARD(v)); }, std::move(test_var)) == "rvalue reference");
}
void test_cpp14_visitor(variant_type&& test_var, variant_type&& test_var2)
{
std::cout << "Testing rvalue visitable for c++14\n";
BOOST_TEST(boost::apply_visitor([](auto&& v, auto&& vv) { return lvalue_rvalue_detector()(FORWARD(v), FORWARD(vv)); }, std::move(test_var), std::move(test_var2))
== "rvalue reference, rvalue reference");
}
void test_cpp14_visitor(variant_type&& test_var, variant_type&& test_var2, variant_type&& test_var3)
{
std::cout << "Testing rvalue visitable for c++14\n";
auto result = boost::apply_visitor([](auto&& v, auto&& t, auto&& p) { return lvalue_rvalue_detector()(FORWARD(v), FORWARD(t), FORWARD(p)); },
std::move(test_var), std::move(test_var2), std::move(test_var3));
std::cout << "result: " << result << std::endl;
BOOST_TEST(result == "rvalue reference, rvalue reference, rvalue reference");
}
#endif // #ifndef BOOST_NO_CXX14_DECLTYPE_AUTO
void run_const_lvalue_ref_tests()
{
const variant_type v1(1), v2(2), v3(3), v4(4);
test_const_ref_parameter(v1);
test_const_ref_parameter2(v1, v2);
test_const_ref_parameter4(v1, v2, v3, v4);
}
void run_rvalue_ref_tests()
{
variant_type v1(10), v2(20), v3(30);
test_rvalue_parameter(std::move(v1));
test_rvalue_parameter2(std::move(v2), std::move(v3));
variant_type vv1(100), vv2(200), vv3(300), vv4(400);
test_rvalue_parameter4(std::move(vv1), std::move(vv2), std::move(vv3), std::move(vv4));
}
void run_mixed_tests()
{
variant_type v1(1), v2(2);
std::cout << "Testing lvalue + rvalue visitable\n";
BOOST_TEST(boost::apply_visitor(lvalue_rvalue_detector(), v1, variant_type(10)) == "lvalue reference, rvalue reference");
std::cout << "Testing rvalue + lvalue visitable\n";
BOOST_TEST(boost::apply_visitor(lvalue_rvalue_detector(), variant_type(10), v1) == "rvalue reference, lvalue reference");
std::cout << "Testing rvalue + lvalue + rvalue visitable\n";
BOOST_TEST(boost::apply_visitor(lvalue_rvalue_detector(), variant_type(10), v1, variant_type(20)) == "rvalue reference, lvalue reference, rvalue reference");
std::cout << "Testing lvalue + rvalue + lvalue + rvalue visitable\n";
BOOST_TEST(boost::apply_visitor(lvalue_rvalue_detector(), v1, variant_type(10), v2, variant_type(20)) == "lvalue reference, rvalue reference, lvalue reference, rvalue reference");
}
void run_cpp14_mixed_tests()
{
#ifndef BOOST_NO_CXX14_DECLTYPE_AUTO
variant_type v1(1), v2(2);
std::cout << "Testing lvalue + rvalue visitable\n";
BOOST_TEST(boost::apply_visitor([](auto&& v, auto&& t) { return lvalue_rvalue_detector()(FORWARD(v), FORWARD(t)); },
v1, variant_type(10)) == "lvalue reference, rvalue reference");
std::cout << "Testing rvalue + lvalue visitable\n";
BOOST_TEST(boost::apply_visitor([](auto&& v, auto&& t) { return lvalue_rvalue_detector()(FORWARD(v), FORWARD(t)); },
variant_type(10), v1) == "rvalue reference, lvalue reference");
std::cout << "Testing rvalue + lvalue + lvalue visitable\n";
BOOST_TEST(boost::apply_visitor([](auto&& v, auto&& t, auto&& p) { return lvalue_rvalue_detector()(FORWARD(v), FORWARD(t), FORWARD(p)); },
variant_type(10), v1, v2) == "rvalue reference, lvalue reference, lvalue reference");
std::cout << "Testing lvalue + rvalue + lvalue visitable\n";
BOOST_TEST(boost::apply_visitor([](auto&& v, auto&& t, auto&& p) { return lvalue_rvalue_detector()(FORWARD(v), FORWARD(t), FORWARD(p)); },
v1, variant_type(10), v2) == "lvalue reference, rvalue reference, lvalue reference");
#endif // #ifndef BOOST_NO_CXX14_DECLTYPE_AUTO
}
void run_cpp14_tests()
{
#ifndef BOOST_NO_CXX14_DECLTYPE_AUTO
variant_type const c1(10), c2(20), c3(30);
variant_type v1(10), v2(20), v3(30);
test_cpp14_visitor(c1);
test_cpp14_mutable_visitor(c1);
test_cpp14_visitor(c2, c3);
test_cpp14_visitor(c1, c2, c3);
test_cpp14_visitor(v1);
test_cpp14_mutable_visitor(v1);
test_cpp14_visitor(v2, v3);
test_cpp14_visitor(v1, v2, v3);
test_cpp14_visitor(std::move(v1));
test_cpp14_visitor(std::move(v2), std::move(v3));
variant_type vv1(100), vv2(200), vv3(300);
test_cpp14_visitor(std::move(vv1), std::move(vv2), std::move(vv3));
#endif
}
int main()
{
run_const_lvalue_ref_tests();
run_rvalue_ref_tests();
run_mixed_tests();
run_cpp14_mixed_tests();
run_cpp14_tests();
return boost::report_errors();
}
+29
View File
@@ -0,0 +1,29 @@
// Copyright (c) 2021-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Test case from https://svn.boost.org/trac10/ticket/8721
#include <boost/variant.hpp>
#include <boost/fusion/include/vector.hpp>
struct emptyList {};
typedef boost::make_recursive_variant
< emptyList
, boost::fusion::vector
< int
, boost::recursive_variant_
>
>::type IntList;
const emptyList el = emptyList();
const IntList nil( el );
IntList cons( int head, IntList tail )
{
return IntList( boost::fusion::vector<int, IntList>( head, tail ) );
}
+73
View File
@@ -0,0 +1,73 @@
// Copyright (c) 2016
// Mikhail Maximov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "boost/config.hpp"
#include "boost/core/lightweight_test.hpp"
#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET)
// Test is based on reported issues:
// https://svn.boost.org/trac/boost/ticket/12508
// https://svn.boost.org/trac/boost/ticket/12645
// Following hash function was not found at compile time,
// because boost::variant construction from boost::recursive_variant_
// was forbidden.
#include <unordered_set>
#include "boost/variant.hpp"
struct hash;
using int_t = int;
template <typename T>
using basic_set_t = std::unordered_set<T, hash>;
using value_t = boost::make_recursive_variant<
int_t,
basic_set_t<boost::recursive_variant_>
>::type;
using set_t = basic_set_t<value_t>;
struct hash
{
size_t operator()(const value_t&) const
{
return 0;
}
};
void run()
{
set_t s;
int_t i = 3;
value_t v = i;
auto emplace_result = s.emplace(v); // raises error above
BOOST_TEST(emplace_result.second);
v = s;
const set_t& check_set = boost::get<set_t>(v);
BOOST_TEST(!check_set.empty());
for (const auto& check_v : check_set) {
BOOST_TEST(s.find(check_v) != s.end());
}
for (const auto& check_v : s) {
BOOST_TEST(check_set.find(check_v) != check_set.end());
}
}
#else // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET)
// if no unordered_set and template aliases - does nothing
void run() {}
#endif
int main()
{
run();
return boost::report_errors();
}
+42 -22
View File
@@ -1,34 +1,54 @@
// Copyright (c) 2011
// Antony Polukhin
// Copyright (c) 2011-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "boost/test/minimal.hpp"
#include "boost/variant/detail/hash_variant.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/config.hpp"
#include "boost/variant.hpp"
#include "boost/functional/hash/hash.hpp"
void run()
{
typedef boost::variant<bool, int, unsigned int, double> variant_type;
boost::hash<variant_type> hasher;
variant_type bool_variant1 = true;
variant_type bool_variant2 = false;
variant_type int_variant = 1;
variant_type float_variant = 1.0;
variant_type uint_variant = static_cast<unsigned int>(1);
#if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET) && !defined(BOOST_VARIANT_DO_NOT_SPECIALIZE_STD_HASH)
BOOST_CHECK(hasher(bool_variant1) != hasher(bool_variant2));
BOOST_CHECK(hasher(bool_variant1) == hasher(bool_variant1));
BOOST_CHECK(hasher(int_variant) != hasher(uint_variant));
BOOST_CHECK(hasher(float_variant) != hasher(uint_variant));
#include <unordered_set>
void test_std_hash() {
std::unordered_set<boost::variant<int, bool> > us;
us.insert(1);
us.insert(true);
BOOST_TEST(us.size() == 2);
}
int test_main(int , char* [])
{
run();
return 0;
#else
void test_std_hash() {}
#endif
void run() {
typedef boost::variant<bool, int, unsigned int, char> variant_type;
boost::hash<variant_type> hasher;
variant_type bool_variant1 = true;
variant_type bool_variant2 = false;
variant_type int_variant = 1;
variant_type char_variant1 = '\1';
variant_type char_variant2 = '\2';
variant_type uint_variant = static_cast<unsigned int>(1);
BOOST_TEST(hasher(bool_variant1) != hasher(bool_variant2));
BOOST_TEST(hasher(bool_variant1) == hasher(bool_variant1));
BOOST_TEST(hasher(int_variant) != hasher(uint_variant));
BOOST_TEST(hasher(char_variant1) != hasher(uint_variant));
BOOST_TEST(hasher(char_variant1) != hasher(char_variant2));
BOOST_TEST(hasher(char_variant1) == hasher(char_variant1));
BOOST_TEST(hasher(char_variant2) == hasher(char_variant2));
}
int main() {
run();
test_std_hash();
return boost::report_errors();
}
+61
View File
@@ -0,0 +1,61 @@
//-----------------------------------------------------------------------------
// boost-libs variant/test/issue42.cpp source file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2018-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Test case from https://github.com/boostorg/variant/issues/42
#include <boost/variant.hpp>
#include <map>
#include <memory>
#include <vector>
#ifdef BOOST_NO_CXX11_SMART_PTR
template <class T> struct shared_ptr_like {};
typedef shared_ptr_like<boost::recursive_variant_> ptr_t;
#else
typedef std::shared_ptr<boost::recursive_variant_> ptr_t;
#endif
template <class F>
class func{};
int main() {
typedef boost::make_recursive_variant<
int,
ptr_t
>::type node;
node x = 1;
(void)x;
typedef boost::make_recursive_variant<
std::string, int, double, bool,
ptr_t,
std::map<const std::string, boost::recursive_variant_>,
std::vector<boost::recursive_variant_>
>::type node2;
node2 x2 = 1;
(void)x2;
typedef boost::make_recursive_variant<
int,
func<boost::recursive_variant_(*)(boost::recursive_variant_&, const boost::recursive_variant_&)>,
boost::recursive_variant_&(*)(boost::recursive_variant_, boost::recursive_variant_*),
ptr_t
>::type node3;
node3 x3 = func<node3(*)(node3&, const node3&)>();
(void)x3;
}
+58
View File
@@ -0,0 +1,58 @@
//-----------------------------------------------------------------------------
// boost-libs variant/test/issue53.cpp source file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2019-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Test case from https://github.com/boostorg/variant/issues/53
#include <boost/variant.hpp>
#include <boost/thread/lock_guard.hpp> // this line was causing problems on MSVC
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
struct spanac {};
struct ceapa{
double a,b;
};
typedef boost::variant<spanac, ceapa> var_t;
struct visitor_t : public boost::static_visitor<bool> {
bool operator() (const spanac&) const {
return true;
}
bool operator() (const ceapa&) const {
return false;
}
private:
double a, b;
};
var_t get(int k) {
if (k)
return spanac();
else
return ceapa();
}
int main(int argc, const char** argv) {
visitor_t v;
bool result = boost::apply_visitor(v, get(argc - 1));
(void)result;
}
#else // #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
int main() {}
#endif // #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+16 -19
View File
@@ -25,8 +25,9 @@
#include "boost/variant/apply_visitor.hpp"
#include "boost/variant/static_visitor.hpp"
#include "boost/type_index.hpp"
#include "boost/detail/workaround.hpp"
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0551))
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x0551))
# pragma warn -lvc
#endif
@@ -243,16 +244,14 @@ inline void verify(VariantType& var, spec<S>, std::string str = "")
{
const VariantType& cvar = var;
BOOST_CHECK(boost::apply_visitor(total_sizeof(), cvar) == sizeof(S));
#if !defined(BOOST_NO_TYPEID)
BOOST_CHECK(cvar.type() == typeid(S));
#endif
BOOST_TEST(boost::apply_visitor(total_sizeof(), cvar) == sizeof(S));
BOOST_TEST(cvar.type() == boost::typeindex::type_id<S>());
//
// Check get<>()
//
BOOST_CHECK(boost::get<S>(&var));
BOOST_CHECK(boost::get<S>(&cvar));
BOOST_TEST(boost::get<S>(&var));
BOOST_TEST(boost::get<S>(&cvar));
const S* ptr1 = 0;
const S* ptr2 = 0;
@@ -261,7 +260,7 @@ inline void verify(VariantType& var, spec<S>, std::string str = "")
S& r = boost::get<S>(var);
ptr1 = &r;
}
catch(boost::bad_get& )
catch(const boost::bad_get& )
{
BOOST_ERROR( "get<S> failed unexpectedly" );
}
@@ -271,12 +270,12 @@ inline void verify(VariantType& var, spec<S>, std::string str = "")
const S& cr = boost::get<S>(cvar);
ptr2 = &cr;
}
catch(boost::bad_get& )
catch(const boost::bad_get& )
{
BOOST_ERROR( "get<S> const failed unexpectedly" );
}
BOOST_CHECK(ptr1 != 0 && ptr2 == ptr1);
BOOST_TEST(ptr1 != 0 && ptr2 == ptr1);
//
// Check string content
@@ -285,7 +284,7 @@ inline void verify(VariantType& var, spec<S>, std::string str = "")
{
std::string temp = boost::apply_visitor(to_text(), cvar);
std::cout << "temp = " << temp << ", str = " << str << std::endl;
BOOST_CHECK(temp == str);
BOOST_TEST(temp == str);
}
}
@@ -295,15 +294,13 @@ inline void verify_not(VariantType& var, spec<S>)
{
const VariantType& cvar = var;
#if !defined(BOOST_NO_TYPEID)
BOOST_CHECK(cvar.type() != typeid(S));
#endif
BOOST_TEST(cvar.type() != boost::typeindex::type_id<S>());
//
// Check get<>()
//
BOOST_CHECK(!boost::get<S>(&var));
BOOST_CHECK(!boost::get<S>(&cvar));
BOOST_TEST(!boost::get<S>(&var));
BOOST_TEST(!boost::get<S>(&cvar));
const S* ptr1 = 0;
const S* ptr2 = 0;
@@ -314,7 +311,7 @@ inline void verify_not(VariantType& var, spec<S>)
ptr1 = &r;
}
catch(boost::bad_get& )
catch(const boost::bad_get& )
{
// do nothing except pass-through
}
@@ -326,12 +323,12 @@ inline void verify_not(VariantType& var, spec<S>)
ptr2 = &cr;
}
catch(boost::bad_get& )
catch(const boost::bad_get& )
{
// do nothing except pass-through
}
BOOST_CHECK(ptr1 == 0 && ptr2 == 0);
BOOST_TEST(ptr1 == 0 && ptr2 == 0);
}
+32
View File
@@ -0,0 +1,32 @@
// Copyright (c) 2017-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "boost/config.hpp"
#include "boost/variant.hpp"
struct foo {};
struct some_user_provided_visitor_for_lvalues: boost::static_visitor<void> {
void operator()(foo& ) const {}
void operator()(int ) const {}
};
int main() {
boost::apply_visitor(
some_user_provided_visitor_for_lvalues(),
boost::variant<int, foo>(foo())
);
#ifdef __GNUC__
# if __GNUC__ < 5 && __GNUC_MINOR__ < 8
# error This test does not pass on GCC < 4.8 because of the incomplete C++11 support
# endif
#endif
#ifdef BOOST_MSVC
# error Temporaries/rvalues could bind to non-const lvalues on MSVC compilers
#endif
}
+215
View File
@@ -0,0 +1,215 @@
//-----------------------------------------------------------------------------
// boost-libs variant/test/variant_get_test.cpp source file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2016-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// This test suite was created to cover issues reported in:
// https://svn.boost.org/trac/boost/ticket/5871
// https://svn.boost.org/trac/boost/ticket/11602
#include "boost/variant/variant.hpp"
#include "boost/variant/recursive_variant.hpp"
#include "boost/core/lightweight_test.hpp"
#include <string>
#include <list>
struct A{};
struct B{};
struct C{};
struct D{};
bool foo(const boost::variant<A, B>& ) {
return false;
}
bool foo(const boost::variant<C, D>& ) {
return true;
}
void test_overload_selection_variant_constructor() {
D d;
BOOST_TEST(foo(d));
boost::variant<B, A> v;
BOOST_TEST(!foo(v));
}
// Pre msvc-14.0 could not dustinguish between multiple assignment operators:
// warning C4522: 'assignment_tester' : multiple assignment operators specified
// error C2666: variant::operator =' : 3 overloads have similar conversions
// Old versions of GCC have same issue:
// error: variant::operator=(const T&) cannot be overloaded
#if (defined(__GNUC__) && (__GNUC__ < 4)) || (defined(_MSC_VER) && _MSC_VER < 1900)
void test_overload_selection_variant_assignment() {
BOOST_TEST(true);
}
#else
struct assignment_tester: boost::variant<C, D>, boost::variant<B, A> {
using boost::variant<B, A>::operator=;
using boost::variant<C, D>::operator=;
};
void test_overload_selection_variant_assignment() {
A a;
assignment_tester tester;
tester = a;
const int which0 = static_cast< boost::variant<B, A>& >(tester).which();
BOOST_TEST(which0 == 1);
boost::variant<A, B> b;
b = B();
tester = b;
const int which1 = static_cast< boost::variant<B, A>& >(tester).which();
BOOST_TEST(which1 == 0);
}
#endif
typedef boost::variant<int> my_variant;
struct convertible {
operator my_variant() const {
return my_variant();
}
};
void test_implicit_conversion_operator() {
// https://svn.boost.org/trac/boost/ticket/8555
my_variant y = convertible();
BOOST_TEST(y.which() == 0);
}
struct X: boost::variant< int > {};
class V1: public boost::variant<float,double> {};
struct AB: boost::variant<A, B> {};
void test_derived_from_variant_construction() {
// https://svn.boost.org/trac/boost/ticket/7120
X x;
boost::variant<X> y(x);
BOOST_TEST(y.which() == 0);
// https://svn.boost.org/trac/boost/ticket/10278
boost::variant<V1, std::string> v2 = V1();
BOOST_TEST(v2.which() == 0);
// https://svn.boost.org/trac/boost/ticket/12155
AB ab;
boost::variant<AB, C> ab_c(ab);
BOOST_TEST(ab_c.which() == 0);
boost::variant<A, B> a_b(ab);
BOOST_TEST(a_b.which() == 0);
boost::variant<B, C, A> b_c_a1(static_cast<boost::variant<A, B>& >(ab));
BOOST_TEST(b_c_a1.which() == 2);
// Following conversion seems harmful as it may lead to slicing:
// boost::variant<B, C, A> b_c_a(ab);
// BOOST_TEST(b_c_a.which() == 2);
}
void test_derived_from_variant_assignment() {
// https://svn.boost.org/trac/boost/ticket/7120
X x;
boost::variant<X> y;
y = x;
BOOST_TEST(y.which() == 0);
// https://svn.boost.org/trac/boost/ticket/10278
boost::variant<V1, std::string> v2;
v2 = V1();
BOOST_TEST(v2.which() == 0);
// https://svn.boost.org/trac/boost/ticket/12155
AB ab;
boost::variant<AB, C> ab_c;
ab_c = ab;
BOOST_TEST(ab_c.which() == 0);
boost::variant<A, B> a_b;
a_b = ab;
BOOST_TEST(a_b.which() == 0);
boost::variant<B, C, A> b_c_a1;
b_c_a1 = static_cast<boost::variant<A, B>& >(ab);
BOOST_TEST(b_c_a1.which() == 2);
// Following conversion seems harmful as it may lead to slicing:
// boost::variant<B, C, A> b_c_a;
// b_c_a = ab;
// BOOST_TEST(b_c_a.which() == 2);
}
// http://thread.gmane.org/gmane.comp.lib.boost.devel/267757
struct info {
struct nil_ {};
typedef
boost::variant<
nil_
, std::string
, boost::recursive_wrapper<info>
, boost::recursive_wrapper<std::pair<info, info> >
, boost::recursive_wrapper<std::list<info> >
>
value_type;
value_type v;
inline void test_on_incomplete_types() {
info i0;
i0.v = "Hello";
BOOST_TEST(i0.v.which() == 1);
info::value_type v0 = "Hello";
BOOST_TEST(v0.which() == 1);
info::value_type v1("Hello");
BOOST_TEST(v1.which() == 1);
info::value_type v2 = i0;
BOOST_TEST(v2.which() == 2);
info::value_type v3(i0);
BOOST_TEST(v3.which() == 2);
v0 = v3;
BOOST_TEST(v0.which() == 2);
v3 = v1;
BOOST_TEST(v3.which() == 1);
v3 = nil_();
BOOST_TEST(v3.which() == 0);
}
};
int main()
{
test_overload_selection_variant_constructor();
test_overload_selection_variant_assignment();
test_implicit_conversion_operator();
test_derived_from_variant_construction();
test_derived_from_variant_assignment();
info().test_on_incomplete_types();
return boost::report_errors();
}
+145 -41
View File
@@ -4,7 +4,7 @@
//-----------------------------------------------------------------------------
//
// Copyright (c) 2003 Eric Friedman, Itay Maman
// Copyright (c) 2013 Antony Polukhin
// Copyright (c) 2013-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,27 +18,8 @@
// 2) variant_noexcept_test that tests Boost.Variant ability to compile
// and work with disabled exceptions
#ifdef BOOST_NO_EXCEPTIONS
// `boost/test/minimal.hpp` cannot work with exceptions disabled,
// so we need the following workarounds for that case:
namespace boost {
int exit_success = 0;
}
int test_main(int , char* []);
int main( int argc, char* argv[] )
{
return test_main(argc, argv);
}
#include <stdlib.h>
#define BOOST_CHECK(exp) if (!(exp)) exit(EXIT_FAILURE)
#else // BOOST_NO_EXCEPTIONS
# include "boost/test/minimal.hpp"
#endif // BOOST_NO_EXCEPTIONS
#include "boost/core/lightweight_test.hpp"
#include "boost/variant.hpp"
#include "boost/mpl/vector.hpp"
@@ -48,10 +29,20 @@ int main( int argc, char* argv[] )
#include <sstream>
#include <vector>
#include <map>
#include <tuple>
struct vector_printer
struct Nil {};
struct printer
: boost::static_visitor<std::string>
{
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
std::string operator()(
const boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> &var) const
{
return boost::apply_visitor( printer(), var );
}
template <typename T>
std::string operator()(const std::vector<T>& vec) const
{
@@ -61,13 +52,35 @@ struct vector_printer
typename std::vector<T>::const_iterator it = vec.begin();
for (; it != vec.end(); ++it)
ost << boost::apply_visitor( vector_printer(), *it );
ost << printer()( *it );
ost << ") ";
return ost.str();
}
template <int...> struct indices {};
template <typename... Ts, int... Is>
std::string operator()(const std::tuple<Ts...>& tup, indices<Is...>) const
{
std::ostringstream ost;
ost << "( ";
int a[] = {0, (ost << printer()( std::get<Is>(tup) ), 0)... };
(void)a;
ost << ") ";
return ost.str();
}
template <int N, int... Is>
struct make_indices : make_indices<N-1, N-1, Is...> {};
template <int... Is>
struct make_indices<0, Is...> : indices<Is...> {};
template <typename... Ts>
std::string operator()(const std::tuple<Ts...>& tup) const
{
return printer()(tup, make_indices<sizeof...(Ts)>());
}
template <typename T>
std::string operator()(const T& operand) const
{
@@ -91,10 +104,47 @@ void test_recursive_variant()
vec1.push_back(7);
var1_t var1(vec1);
std::string result1( boost::apply_visitor( vector_printer(), var1 ) );
std::string result1( printer()(var1) );
std::cout << "result1: " << result1 << '\n';
BOOST_CHECK(result1 == "( 3 5 ( 3 5 ) 7 ) ");
BOOST_TEST(result1 == "( 3 5 ( 3 5 ) 7 ) ");
std::vector<var1_t> vec1_copy = vec1;
vec1_copy.erase(vec1_copy.begin() + 2);
vec1_copy.insert(vec1_copy.begin() + 2, vec1_copy);
var1 = vec1_copy;
result1 = printer()(var1);
std::cout << "result1+: " << result1 << '\n';
BOOST_TEST(result1 == "( 3 5 ( 3 5 7 ) 7 ) ");
// Uses move construction on compilers with rvalue references support
result1 = printer()(
var1_t(
std::vector<var1_t>(vec1_copy)
)
);
std::cout << "result1++: " << result1 << '\n';
BOOST_TEST(result1 == "( 3 5 ( 3 5 7 ) 7 ) ");
var1_t vec1_another_copy(vec1_copy);
vec1_copy[2].swap(vec1_another_copy);
result1 = printer()(
var1_t(vec1_copy)
);
std::cout << "result1+++1: " << result1 << '\n';
BOOST_TEST(result1 == "( 3 5 ( 3 5 ( 3 5 7 ) 7 ) 7 ) ");
result1 = printer()(vec1_another_copy);
std::cout << "result1++2: " << result1 << '\n';
BOOST_TEST(result1 == "( 3 5 7 ) ");
vec1_copy[2].swap(vec1_copy[2]);
result1 = printer()(
var1_t(vec1_copy)
);
std::cout << "result1.2: " << result1 << '\n';
BOOST_TEST(result1 == "( 3 5 ( 3 5 ( 3 5 7 ) 7 ) 7 ) ");
typedef boost::make_recursive_variant<
boost::variant<int, double>
@@ -108,10 +158,10 @@ void test_recursive_variant()
vec2.push_back(boost::variant<int, double>(7));
var2_t var2(vec2);
std::string result2( boost::apply_visitor( vector_printer(), var2 ) );
std::string result2( printer()(var2) );
std::cout << "result2: " << result2 << '\n';
BOOST_CHECK(result2 == "( 3 3.5 ( 3 3.5 ) 7 ) ");
BOOST_TEST(result2 == "( 3 3.5 ( 3 3.5 ) 7 ) ");
typedef boost::make_recursive_variant<
int
@@ -135,10 +185,10 @@ void test_recursive_variant()
vec3.push_back(7);
var4_t var4(vec3);
std::string result3( boost::apply_visitor( vector_printer(), var4 ) );
std::string result3( printer()(var4) );
std::cout << "result2: " << result3 << '\n';
BOOST_CHECK(result3 == "( 3 5 ( 3.5 ( 3 5 ) ) 7 ) ");
BOOST_TEST(result3 == "( 3 5 ( 3.5 ( 3 5 ) ) 7 ) ");
typedef boost::make_recursive_variant<
double,
@@ -150,16 +200,29 @@ void test_recursive_variant()
vec5.push_back(vec1);
vec5.push_back(17.25);
std::string result5( vector_printer()(vec5) );
std::string result5( printer()(vec5) );
std::cout << "result5: " << result5 << '\n';
BOOST_CHECK(result5 == "( 3.5 ( 3 5 ( 3 5 ) 7 ) 17.25 ) ");
BOOST_TEST(result5 == "( 3.5 ( 3 5 ( 3 5 ) 7 ) 17.25 ) ");
typedef boost::make_recursive_variant<
int,
std::map<int, boost::recursive_variant_>
>::type var6_t;
var6_t var6;
typedef boost::make_recursive_variant<
int,
std::tuple<int, boost::recursive_variant_>
>::type var7_t;
var7_t var7 = 0; // !!! Do not replace with `var7_t var7{0}` or `var7_t var7(0)` !!!
var7 = std::tuple<int, var7_t>(1, var7);
var7 = std::tuple<int, var7_t>(2, var7);
std::string result7( printer()(var7) );
std::cout << "result7: " << result7 << '\n';
BOOST_TEST(result7 == "( 2 ( 1 0 ) ) ");
}
void test_recursive_variant_over()
@@ -178,10 +241,40 @@ void test_recursive_variant_over()
vec1.push_back(7);
var1_t var1(vec1);
std::string result1( boost::apply_visitor( vector_printer(), var1 ) );
std::string result1( printer()(var1) );
std::cout << "result1: " << result1 << '\n';
BOOST_CHECK(result1 == "( 3 5 ( 3 5 ) 7 ) ");
BOOST_TEST(result1 == "( 3 5 ( 3 5 ) 7 ) ");
std::vector<var1_t> vec1_copy = vec1;
vec1_copy.erase(vec1_copy.begin() + 2);
vec1_copy.insert(vec1_copy.begin() + 2, vec1_copy);
var1 = vec1_copy;
result1 = printer()(var1);
std::cout << "result1+: " << result1 << '\n';
BOOST_TEST(result1 == "( 3 5 ( 3 5 7 ) 7 ) ");
// Uses move construction on compilers with rvalue references support
result1 = printer()(
var1_t(
std::vector<var1_t>(vec1_copy)
)
);
std::cout << "result1++: " << result1 << '\n';
BOOST_TEST(result1 == "( 3 5 ( 3 5 7 ) 7 ) ");
var1_t vec1_another_copy(vec1_copy);
vec1_copy[2].swap(vec1_another_copy);
result1 = printer()(
var1_t(vec1_copy)
);
std::cout << "result1+++1: " << result1 << '\n';
BOOST_TEST(result1 == "( 3 5 ( 3 5 ( 3 5 7 ) 7 ) 7 ) ");
result1 = printer()(vec1_another_copy);
std::cout << "result1++2: " << result1 << '\n';
BOOST_TEST(result1 == "( 3 5 7 ) ");
typedef boost::make_recursive_variant_over<
boost::mpl::vector<
@@ -197,10 +290,10 @@ void test_recursive_variant_over()
vec2.push_back(boost::variant<int, double>(7));
var2_t var2(vec2);
std::string result2( boost::apply_visitor( vector_printer(), var2 ) );
std::string result2( printer()(var2) );
std::cout << "result2: " << result2 << '\n';
BOOST_CHECK(result2 == "( 3 3.5 ( 3 3.5 ) 7 ) ");
BOOST_TEST(result2 == "( 3 3.5 ( 3 3.5 ) 7 ) ");
typedef boost::make_recursive_variant_over<
boost::mpl::vector<
@@ -235,10 +328,10 @@ void test_recursive_variant_over()
vec3.push_back(7);
var4_t var3(vec3);
std::string result3( boost::apply_visitor( vector_printer(), var3 ) );
std::string result3( printer()(var3) );
std::cout << "result2: " << result3 << '\n';
BOOST_CHECK(result3 == "( 3 5 ( 3.5 ( 3 5 ) ) 7 ) ");
BOOST_TEST(result3 == "( 3 5 ( 3.5 ( 3 5 ) ) 7 ) ");
typedef boost::make_recursive_variant_over<
boost::mpl::vector<
@@ -252,16 +345,27 @@ void test_recursive_variant_over()
vec5.push_back(vec1);
vec5.push_back(17.25);
std::string result5( vector_printer()(vec5) );
std::string result5( printer()(vec5) );
std::cout << "result5: " << result5 << '\n';
BOOST_CHECK(result5 == "( 3.5 ( 3 5 ( 3 5 ) 7 ) 17.25 ) ");
BOOST_TEST(result5 == "( 3.5 ( 3 5 ( 3 5 ) 7 ) 17.25 ) ");
}
int test_main(int , char* [])
void test_recursive_variant_from_variant()
{
// See https://github.com/boostorg/variant/issues/100
typedef boost::variant<Nil, double> Atom;
typedef boost::variant<Nil, boost::recursive_wrapper<Atom> > Variant;
BOOST_STATIC_ASSERT(!boost::is_constructible<Variant, Atom>::value);
BOOST_STATIC_ASSERT(boost::is_constructible<boost::variant<Nil, Atom>, Atom>::value);
}
int main()
{
test_recursive_variant();
test_recursive_variant_over();
test_recursive_variant_from_variant();
return boost::exit_success;
return boost::report_errors();
}
+77
View File
@@ -0,0 +1,77 @@
// Copyright (c) 2017
// Mikhail Maximov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "boost/config.hpp"
#include "boost/core/lightweight_test.hpp"
#ifdef __cpp_inheriting_constructors
// Test is based on reported issue:
// https://svn.boost.org/trac/boost/ticket/12680
// GCC 6 crashed, trying to determine is boost::recursive_wrapper<Node>
// is_noexcept_move_constructible
#include <string>
#include <boost/variant.hpp>
#include <boost/array.hpp>
struct Leaf { };
struct Node;
typedef boost::variant<Leaf, boost::recursive_wrapper<Node>> TreeBase;
struct Tree : TreeBase {
using TreeBase::TreeBase;
template <typename Iter>
static Tree Create(Iter /*first*/, Iter /*last*/) { return Leaf{}; }
};
struct Node {
Tree left, right;
};
// Test from https://svn.boost.org/trac/boost/ticket/7120
template<class Node>
struct node1_type;
struct var_type;
using var_base = boost::variant<int,
boost::recursive_wrapper<node1_type<var_type>>
>;
template<class Node>
struct node1_type {
boost::array<Node, 1> children;
};
struct var_type : var_base {
using var_base::var_base;
};
void run() {
std::string input{"abracadabra"};
const Tree root = Tree::Create(input.begin(), input.end());
(void)root; // prevents unused variable warning
var_type v1 = 1;
(void)v1;
}
#else // #!ifdef __cpp_inheriting_constructors
// if compiler does not support inheriting constructors - does nothing
void run() {}
#endif
int main()
{
run();
return boost::report_errors();
}
+97 -92
View File
@@ -3,7 +3,7 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2012-2013 Antony Polukhin
// Copyright (c) 2012-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -11,24 +11,38 @@
#include "boost/config.hpp"
#include "boost/test/minimal.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/variant.hpp"
#include "boost/type_traits/is_nothrow_move_assignable.hpp"
#include "boost/mpl/bool.hpp"
#include <boost/blank.hpp>
namespace swap_ambiguouty_test_ns {
struct A {};
struct B {};
void swap_ambiguouty_test() {
// If boost::blank is not used, then it compiles.
typedef boost::variant<boost::blank, A, B> Variant;
Variant v1, v2;
swap(v1, v2);
}
} // namespace swap_ambiguouty_test_ns
// Most part of tests from this file require rvalue references support
class move_copy_conting_class {
public:
static unsigned int moves_count;
static unsigned int copy_count;
move_copy_conting_class(){}
move_copy_conting_class(BOOST_RV_REF(move_copy_conting_class) ) {
move_copy_conting_class(move_copy_conting_class&& ) {
++ moves_count;
}
move_copy_conting_class& operator=(BOOST_RV_REF(move_copy_conting_class) ) {
move_copy_conting_class& operator=(move_copy_conting_class&& ) {
++ moves_count;
return *this;
}
@@ -36,7 +50,7 @@ public:
move_copy_conting_class(const move_copy_conting_class&) {
++ copy_count;
}
move_copy_conting_class& operator=(BOOST_COPY_ASSIGN_REF(move_copy_conting_class) ) {
move_copy_conting_class& operator=(const move_copy_conting_class& ) {
++ copy_count;
return *this;
}
@@ -45,65 +59,18 @@ public:
unsigned int move_copy_conting_class::moves_count = 0;
unsigned int move_copy_conting_class::copy_count = 0;
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
void run()
{
// Making sure that internals of Boost.Move do not interfere with
// internals of Boost.Variant and in case of C++03 or C++98 compilation
// is still possible.
typedef boost::variant<int, move_copy_conting_class> variant_I_type;
variant_I_type v1, v2;
v1 = move_copy_conting_class();
v2 = v1;
v2 = boost::move(v1);
v1.swap(v2);
move_copy_conting_class val;
v2 = boost::move(val);
v2 = 10;
variant_I_type v3(boost::move(val));
variant_I_type v4(boost::move(v1));
}
void run1()
{
BOOST_CHECK(true);
}
void run_move_only()
{
BOOST_CHECK(true);
}
void run_moves_are_noexcept()
{
BOOST_CHECK(true);
}
void run_const_rvalues()
{
BOOST_CHECK(true);
}
#else
void run()
{
typedef boost::variant<int, move_copy_conting_class> variant_I_type;
variant_I_type v1, v2;
// Assuring that `move_copy_conting_class` was not created
BOOST_CHECK(move_copy_conting_class::copy_count == 0);
BOOST_CHECK(move_copy_conting_class::moves_count == 0);
BOOST_TEST(move_copy_conting_class::copy_count == 0);
BOOST_TEST(move_copy_conting_class::moves_count == 0);
v1 = move_copy_conting_class();
// Assuring that `move_copy_conting_class` was moved at least once
BOOST_CHECK(move_copy_conting_class::moves_count != 0);
BOOST_TEST(move_copy_conting_class::moves_count != 0);
unsigned int total_count = move_copy_conting_class::moves_count + move_copy_conting_class::copy_count;
move_copy_conting_class var;
@@ -112,57 +79,57 @@ void run()
move_copy_conting_class::copy_count = 0;
v1 = var;
// Assuring that move assignment operator moves/copyes value not more times than copy assignment operator
BOOST_CHECK(total_count <= move_copy_conting_class::moves_count + move_copy_conting_class::copy_count);
BOOST_TEST(total_count <= move_copy_conting_class::moves_count + move_copy_conting_class::copy_count);
move_copy_conting_class::moves_count = 0;
move_copy_conting_class::copy_count = 0;
v2 = boost::move(v1);
v2 = std::move(v1);
// Assuring that `move_copy_conting_class` in v1 was moved at least once and was not copied
BOOST_CHECK(move_copy_conting_class::moves_count != 0);
BOOST_CHECK(move_copy_conting_class::copy_count == 0);
BOOST_TEST(move_copy_conting_class::moves_count != 0);
BOOST_TEST(move_copy_conting_class::copy_count == 0);
v1 = move_copy_conting_class();
move_copy_conting_class::moves_count = 0;
move_copy_conting_class::copy_count = 0;
v2 = boost::move(v1);
v2 = std::move(v1);
// Assuring that `move_copy_conting_class` in v1 was moved at least once and was not copied
BOOST_CHECK(move_copy_conting_class::moves_count != 0);
BOOST_CHECK(move_copy_conting_class::copy_count == 0);
BOOST_TEST(move_copy_conting_class::moves_count != 0);
BOOST_TEST(move_copy_conting_class::copy_count == 0);
total_count = move_copy_conting_class::moves_count + move_copy_conting_class::copy_count;
move_copy_conting_class::moves_count = 0;
move_copy_conting_class::copy_count = 0;
v1 = v2;
// Assuring that move assignment operator moves/copyes value not more times than copy assignment operator
BOOST_CHECK(total_count <= move_copy_conting_class::moves_count + move_copy_conting_class::copy_count);
BOOST_TEST(total_count <= move_copy_conting_class::moves_count + move_copy_conting_class::copy_count);
typedef boost::variant<move_copy_conting_class, int> variant_II_type;
variant_II_type v3;
move_copy_conting_class::moves_count = 0;
move_copy_conting_class::copy_count = 0;
v1 = boost::move(v3);
v1 = std::move(v3);
// Assuring that `move_copy_conting_class` in v3 was moved at least once (v1 and v3 have different types)
BOOST_CHECK(move_copy_conting_class::moves_count != 0);
BOOST_TEST(move_copy_conting_class::moves_count != 0);
move_copy_conting_class::moves_count = 0;
move_copy_conting_class::copy_count = 0;
v2 = boost::move(v1);
v2 = std::move(v1);
// Assuring that `move_copy_conting_class` in v1 was moved at least once (v1 and v3 have different types)
BOOST_CHECK(move_copy_conting_class::moves_count != 0);
BOOST_TEST(move_copy_conting_class::moves_count != 0);
move_copy_conting_class::moves_count = 0;
move_copy_conting_class::copy_count = 0;
variant_I_type v5(boost::move(v1));
variant_I_type v5(std::move(v1));
// Assuring that `move_copy_conting_class` in v1 was moved at least once and was not copied
BOOST_CHECK(move_copy_conting_class::moves_count != 0);
BOOST_CHECK(move_copy_conting_class::copy_count == 0);
BOOST_TEST(move_copy_conting_class::moves_count != 0);
BOOST_TEST(move_copy_conting_class::copy_count == 0);
total_count = move_copy_conting_class::moves_count + move_copy_conting_class::copy_count;
move_copy_conting_class::moves_count = 0;
move_copy_conting_class::copy_count = 0;
variant_I_type v6(v1);
// Assuring that move constructor moves/copyes value not more times than copy constructor
BOOST_CHECK(total_count <= move_copy_conting_class::moves_count + move_copy_conting_class::copy_count);
BOOST_TEST(total_count <= move_copy_conting_class::moves_count + move_copy_conting_class::copy_count);
}
void run1()
@@ -172,11 +139,11 @@ void run1()
move_copy_conting_class c1;
typedef boost::variant<int, move_copy_conting_class> variant_I_type;
variant_I_type v1(boost::move(c1));
variant_I_type v1(std::move(c1));
// Assuring that `move_copy_conting_class` was not copyied
BOOST_CHECK(move_copy_conting_class::copy_count == 0);
BOOST_CHECK(move_copy_conting_class::moves_count > 0);
BOOST_TEST(move_copy_conting_class::copy_count == 0);
BOOST_TEST(move_copy_conting_class::moves_count > 0);
}
struct move_only_structure {
@@ -189,32 +156,51 @@ private:
move_only_structure& operator=(const move_only_structure&);
};
struct visitor_returning_move_only_type: boost::static_visitor<move_only_structure> {
template <class T>
move_only_structure operator()(const T&) const {
return move_only_structure();
}
};
void run_move_only()
{
move_only_structure mo;
boost::variant<int, move_only_structure > vi, vi2(static_cast<move_only_structure&&>(mo));
BOOST_CHECK(vi.which() == 0);
BOOST_CHECK(vi2.which() == 1);
BOOST_TEST(vi.which() == 0);
BOOST_TEST(vi2.which() == 1);
vi = 10;
vi2 = 10;
BOOST_CHECK(vi.which() == 0);
BOOST_CHECK(vi2.which() == 0);
BOOST_TEST(vi.which() == 0);
BOOST_TEST(vi2.which() == 0);
vi = static_cast<move_only_structure&&>(mo);
vi2 = static_cast<move_only_structure&&>(mo);
BOOST_CHECK(vi.which() == 1);
BOOST_TEST(vi.which() == 1);
boost::variant<move_only_structure, int > rvi (1);
BOOST_TEST(rvi.which() == 1);
rvi = static_cast<move_only_structure&&>(mo);
BOOST_TEST(rvi.which() == 0);
rvi = 1;
BOOST_TEST(rvi.which() == 1);
rvi = static_cast<boost::variant<int, move_only_structure >&&>(vi2);
BOOST_TEST(rvi.which() == 0);
move_only_structure from_visitor = boost::apply_visitor(visitor_returning_move_only_type(), vi);
(void)from_visitor;
}
void run_moves_are_noexcept() {
#ifndef BOOST_NO_CXX11_NOEXCEPT
#if !defined(BOOST_NO_CXX11_NOEXCEPT) && (!defined(__GNUC__) || defined(__clang__) || __GNUC__ > 4 || __GNUC_MINOR__ >= 8)
typedef boost::variant<int, short, double> variant_noexcept_t;
//BOOST_CHECK(boost::is_nothrow_move_assignable<variant_noexcept_t>::value);
BOOST_CHECK(boost::is_nothrow_move_constructible<variant_noexcept_t>::value);
BOOST_TEST(boost::is_nothrow_move_assignable<variant_noexcept_t>::value);
BOOST_TEST(boost::is_nothrow_move_constructible<variant_noexcept_t>::value);
typedef boost::variant<int, short, double, move_only_structure> variant_except_t;
//BOOST_CHECK(!boost::is_nothrow_move_assignable<variant_except_t>::value);
BOOST_CHECK(!boost::is_nothrow_move_constructible<variant_except_t>::value);
BOOST_TEST(!boost::is_nothrow_move_assignable<variant_except_t>::value);
BOOST_TEST(!boost::is_nothrow_move_constructible<variant_except_t>::value);
#endif
}
@@ -233,19 +219,16 @@ void run_const_rvalues()
v4 = get_string();
v5 = get_variant();
v6 = get_variant2();
v7 = boost::move(v1);
v7 = std::move(v1);
}
#endif
struct nothrow_copyable_throw_movable {
nothrow_copyable_throw_movable(){}
nothrow_copyable_throw_movable(const nothrow_copyable_throw_movable&) BOOST_NOEXCEPT {}
nothrow_copyable_throw_movable& operator=(const nothrow_copyable_throw_movable&) BOOST_NOEXCEPT { return *this; }
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
nothrow_copyable_throw_movable(nothrow_copyable_throw_movable&&) BOOST_NOEXCEPT_IF(false) {}
nothrow_copyable_throw_movable& operator=(nothrow_copyable_throw_movable&&) BOOST_NOEXCEPT_IF(false) { return *this; }
#endif
};
// This test is created to cover the following situation:
@@ -256,13 +239,35 @@ void run_tricky_compilation_test()
v = nothrow_copyable_throw_movable();
}
int test_main(int , char* [])
template <typename T>
struct is_container : boost::mpl::false_ {};
template <typename T>
struct is_container<boost::variant<T> > : is_container<T> {};
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct is_container<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
: boost::mpl::bool_<is_container<T0>::value
|| is_container<boost::variant<BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T)> >::value>
{};
void run_is_container_compilation_test()
{
BOOST_TEST((!is_container<boost::variant<double, int> >::value));
BOOST_TEST((!is_container<boost::variant<double, int, char> >::value));
BOOST_TEST((!is_container<boost::variant<double, int, char, float> >::value));
}
int main()
{
swap_ambiguouty_test_ns::swap_ambiguouty_test();
run();
run1();
run_move_only();
run_moves_are_noexcept();
run_tricky_compilation_test();
run_const_rvalues();
return 0;
run_is_container_compilation_test();
return boost::report_errors();
}
+7 -7
View File
@@ -16,7 +16,7 @@
#pragma warning(disable:4244) // conversion from const int to const short
#endif
#include "boost/test/minimal.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/variant.hpp"
#include "class_a.h"
@@ -121,11 +121,11 @@ void run()
v1 = 3.4f;
apply_visitor(ts, v1);
BOOST_CHECK(ts.result() == sizeof(int) + sizeof(double)*2);
BOOST_TEST(ts.result() == sizeof(int) + sizeof(double)*2);
v11 = 5;
string res_s = apply_visitor(int_printer(), v11);
BOOST_CHECK(res_s == "5");
BOOST_TEST(res_s == "5");
//
// A variant object holding an std::vector
@@ -138,13 +138,13 @@ void run()
v11 = int_vec_1;
res_s = apply_visitor(int_printer(), v11);
BOOST_CHECK(res_s == ",512,256,128,64");
BOOST_TEST(res_s == ",512,256,128,64");
}
int test_main(int , char* [])
int main()
{
run();
return 0;
run();
return boost::report_errors();
}
+4 -4
View File
@@ -16,7 +16,7 @@
#pragma warning(disable:4244) // conversion from 'const int' to 'const short'
#endif
#include "boost/test/minimal.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/variant.hpp"
#include "jobs.h"
@@ -141,9 +141,9 @@ void run()
}
int test_main(int , char* [])
int main()
{
run();
return 0;
run();
return boost::report_errors();
}
+6 -8
View File
@@ -10,7 +10,7 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "boost/test/minimal.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/variant.hpp"
#include <iostream>
@@ -113,7 +113,7 @@ struct Calculator : boost::static_visitor<int>
/////////////////////////////////////////////////////////////////////
int test_main(int, char* [])
int main()
{
int n = 13;
@@ -122,15 +122,13 @@ int test_main(int, char* [])
std::ostringstream e1_str;
e1_str << e1;
#if !defined(BOOST_NO_TYPEID)
BOOST_CHECK(e1.type() == typeid(Add));
#endif
BOOST_CHECK(e1_str.str() == "(13+((40+2)-(10+4)))");
BOOST_TEST(e1.type() == boost::typeindex::type_id<Add>());
BOOST_TEST(e1_str.str() == "(13+((40+2)-(10+4)))");
//Evaluate expression
int res = boost::apply_visitor(Calculator(), e1);
BOOST_CHECK(res == n + 28);
BOOST_TEST(res == n + 28);
return 0;
return boost::report_errors();
}
+3 -3
View File
@@ -16,7 +16,7 @@
#pragma warning(disable:4244) // conversion from 'const int' to 'const short'
#endif
#include "boost/test/minimal.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/variant.hpp"
#include "jobs.h"
@@ -32,7 +32,7 @@ typedef variant<std::string, class_a, short> var_type_2;
#include "class_a.h"
int test_main(int , char* [])
int main()
{
using namespace boost;
@@ -53,5 +53,5 @@ int test_main(int , char* [])
v2 = 5;
v1 = v2;
return boost::exit_success;
return boost::report_errors();
}
+6 -6
View File
@@ -10,7 +10,7 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "boost/test/minimal.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/variant.hpp"
#include "jobs.h"
@@ -58,14 +58,14 @@ void run()
verify(v3, spec<int>());
BOOST_CHECK(apply_visitor(sum_int(), v2) == c0);
BOOST_CHECK(apply_visitor(sum_int(), v3) == c0);
BOOST_TEST(apply_visitor(sum_int(), v2) == c0);
BOOST_TEST(apply_visitor(sum_int(), v3) == c0);
sum_int adder;
apply_visitor(adder, v2);
apply_visitor(adder, v3);
BOOST_CHECK(adder.result() == 2*c0);
BOOST_TEST(adder.result() == 2*c0);
//
// A variant holding a variant
@@ -82,9 +82,9 @@ void run()
int test_main(int , char* [])
int main()
{
run();
return 0;
return boost::report_errors();
}
+3 -3
View File
@@ -10,7 +10,7 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "boost/test/minimal.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/variant.hpp"
#include <iostream>
@@ -66,9 +66,9 @@ void run()
int test_main(int , char* [])
int main()
{
run();
return 0;
return boost::report_errors();
}
+11 -11
View File
@@ -16,7 +16,7 @@
#pragma warning(disable:4244) // conversion from 'const int' to 'const short'
#endif
#include "boost/test/minimal.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/variant.hpp"
#include "jobs.h"
@@ -69,8 +69,8 @@ struct Tracker
static void remove(const jas& j)
{
iterator_type iter = s_this_to_sn_.find(&j);
BOOST_CHECK(iter != s_this_to_sn_.end());
BOOST_CHECK( ((*iter).second) == j.sn_);
BOOST_TEST(iter != s_this_to_sn_.end());
BOOST_TEST( ((*iter).second) == j.sn_);
int sn = (*iter).second;
if(sn != j.sn_)
@@ -79,7 +79,7 @@ struct Tracker
<< ", other: this = " << &j << ", j.sn_ = " << j.sn_ << endl;
}
BOOST_CHECK(sn == j.sn_);
BOOST_TEST(sn == j.sn_);
@@ -91,7 +91,7 @@ struct Tracker
static void check()
{
BOOST_CHECK(s_this_to_sn_.empty());
BOOST_TEST(s_this_to_sn_.empty());
}
};
@@ -214,13 +214,13 @@ void var_compare(const VariantType& v, ExpectedType expected)
compare_helper<ExpectedType> ch(expected);
bool checks = boost::apply_visitor(ch, v);
BOOST_CHECK(checks);
BOOST_TEST(checks);
}
void run()
{
variant<string, short> v0;
boost::variant<string, short> v0;
var_compare(v0, string(""));
@@ -230,7 +230,7 @@ void run()
v0 = "penny lane";
var_compare(v0, string("penny lane"));
variant<jas, string, int> v1, v2 = jas(195);
boost::variant<jas, string, int> v1, v2 = jas(195);
var_compare(v1, jas(364));
v1 = jas(500);
@@ -240,16 +240,16 @@ void run()
var_compare(v2, jas(500));
variant<string, int> v3;
boost::variant<string, int> v3;
var_compare(v3, string(""));
}
int test_main(int , char* [])
int main()
{
run();
Tracker::check();
return 0;
return boost::report_errors();
}
+13 -14
View File
@@ -10,14 +10,13 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "boost/test/minimal.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/variant.hpp"
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using namespace boost;
typedef variant<float, std::string, int, std::vector<std::string> > t_var1;
@@ -41,12 +40,12 @@ struct int_sum : static_visitor<>
template <typename T, typename Variant>
T& check_pass(Variant& v, T value)
{
BOOST_CHECK(get<T>(&v));
BOOST_TEST(get<T>(&v));
try
{
T& r = get<T>(v);
BOOST_CHECK(r == value);
BOOST_TEST(r == value);
return r;
}
catch(boost::bad_get&)
@@ -58,21 +57,21 @@ T& check_pass(Variant& v, T value)
template <typename T, typename Variant>
void check_fail(Variant& v)
{
BOOST_CHECK(!get<T>(&v));
BOOST_TEST(!relaxed_get<T>(&v));
try
{
T& r = get<T>(v);
T& r = relaxed_get<T>(v);
(void)r; // suppress warning about r not being used
BOOST_CHECK(false && &r); // should never reach
BOOST_TEST(false && relaxed_get<T>(&v)); // should never reach
}
catch(boost::bad_get&)
catch(const boost::bad_get& e)
{
// (do nothing here)
BOOST_TEST(!!e.what()); // make sure that what() is const qualified and returnes something
}
}
int test_main(int , char* [])
int main()
{
int_sum acc;
t_var1 v1 = 800;
@@ -88,12 +87,12 @@ int test_main(int , char* [])
check_fail<const short>(v1);
apply_visitor(acc, v1);
BOOST_CHECK(acc.result_ == 800);
BOOST_TEST(acc.result_ == 800);
r1 = 920; // NOTE: modifies content of v1
apply_visitor(acc, v1);
BOOST_CHECK(cr1 == 920);
BOOST_CHECK(acc.result_ == 800 + 920);
BOOST_TEST(cr1 == 920);
BOOST_TEST(acc.result_ == 800 + 920);
}
// check const correctness:
@@ -109,6 +108,6 @@ int test_main(int , char* [])
//check_fail<short>(c);
}
return boost::exit_success;
return boost::report_errors();
}
+22
View File
@@ -0,0 +1,22 @@
//-----------------------------------------------------------------------------
// boost-libs variant/test/test9.cpp source file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2016-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Test from https://github.com/boostorg/variant/pull/21
#include <boost/fusion/container/vector.hpp>
#include <boost/fusion/mpl.hpp>
#include <boost/variant/variant.hpp>
int main() {
boost::make_variant_over<boost::fusion::vector<int, char> >::type t;
(void)t;
}
+68 -31
View File
@@ -3,15 +3,15 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2003
// Eric Friedman, Itay Maman
// Copyright (c) 2003 Eric Friedman, Itay Maman
// Copyright (c) 2014-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "boost/variant/variant.hpp"
#include "boost/test/minimal.hpp"
#include "boost/core/lightweight_test.hpp"
#include <iostream>
#include <sstream>
@@ -21,7 +21,7 @@
#include <vector>
#include "boost/detail/workaround.hpp"
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0551))
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x0551))
# pragma warn -lvc // temporary used for parameter warning
#endif
@@ -31,29 +31,38 @@ void assert_equality_comparable(
)
{
// identity check
BOOST_CHECK( !(&x == &y) || (x == y) );
BOOST_CHECK( !(&x == &z) || (x == z) );
BOOST_CHECK( !(&y == &z) || (y == z) );
BOOST_TEST( !(&x == &y) || (x == y) );
BOOST_TEST( !(&x == &z) || (x == z) );
BOOST_TEST( !(&y == &z) || (y == z) );
BOOST_TEST( !(&x == &y) || !(x != y) );
BOOST_TEST( !(&x == &z) || !(x != z) );
BOOST_TEST( !(&y == &z) || !(y != z) );
// reflexivity check
BOOST_CHECK( (x == x) );
BOOST_CHECK( (y == y) );
BOOST_CHECK( (z == z) );
BOOST_TEST( (x == x) );
BOOST_TEST( (y == y) );
BOOST_TEST( (z == z) );
// symmetry check
BOOST_CHECK( !(x == y) || (y == x) );
BOOST_CHECK( !(y == x) || (x == y) );
BOOST_TEST( !(x == y) || (y == x) );
BOOST_TEST( !(y == x) || (x == y) );
BOOST_TEST( (x != y) || (y == x) );
BOOST_TEST( (y != x) || (x == y) );
BOOST_CHECK( !(x == z) || (z == x) );
BOOST_CHECK( !(z == x) || (x == z) );
BOOST_TEST( !(x == z) || (z == x) );
BOOST_TEST( !(z == x) || (x == z) );
BOOST_TEST( (x != z) || (z == x) );
BOOST_TEST( (z != x) || (x == z) );
BOOST_CHECK( !(y == z) || (z == y) );
BOOST_CHECK( !(z == y) || (y == z) );
BOOST_TEST( !(y == z) || (z == y) );
BOOST_TEST( !(z == y) || (y == z) );
BOOST_TEST( (y != z) || (z == y) );
BOOST_TEST( (z != y) || (y == z) );
// transitivity check
BOOST_CHECK( !(x == y && y == z) || (x == z) );
BOOST_CHECK( !(x == z && z == y) || (x == y) );
BOOST_CHECK( !(y == z && z == x) || (y == x) );
BOOST_TEST( !(x == y && y == z) || (x == z) );
BOOST_TEST( !(x == z && z == y) || (x == y) );
BOOST_TEST( !(y == z && z == x) || (y == x) );
}
template <typename T>
@@ -62,19 +71,41 @@ void assert_less_than_comparable(
)
{
// irreflexivity check
BOOST_CHECK( !(x < x) );
BOOST_CHECK( !(y < y) );
BOOST_CHECK( !(z < z) );
BOOST_TEST( !(x < x) );
BOOST_TEST( !(y < y) );
BOOST_TEST( !(z < z) );
BOOST_TEST( !(x > x) );
BOOST_TEST( !(y > y) );
BOOST_TEST( !(z > z) );
BOOST_TEST( (x <= x) );
BOOST_TEST( (y <= y) );
BOOST_TEST( (z <= z) );
BOOST_TEST( (x >= x) );
BOOST_TEST( (y >= y) );
BOOST_TEST( (z >= z) );
// transitivity check
BOOST_CHECK( (x < y) );
BOOST_CHECK( (y < z) );
BOOST_CHECK( (x < z) );
BOOST_TEST( (x < y) );
BOOST_TEST( (y < z) );
BOOST_TEST( (x < z) );
BOOST_TEST( (x <= y) );
BOOST_TEST( (y <= z) );
BOOST_TEST( (x <= z) );
BOOST_TEST( (z > y) );
BOOST_TEST( (y > x) );
BOOST_TEST( (z > x) );
BOOST_TEST( (z >= y) );
BOOST_TEST( (y >= x) );
BOOST_TEST( (z >= x) );
// antisymmetry check
BOOST_CHECK( !(y < x) );
BOOST_CHECK( !(z < y) );
BOOST_CHECK( !(z < x) );
BOOST_TEST( !(y < x) );
BOOST_TEST( !(z < y) );
BOOST_TEST( !(z < x) );
}
template <typename It>
@@ -91,7 +122,7 @@ std::string print_range(It first, It last)
return result.str();
}
int test_main(int , char* [])
int main()
{
typedef boost::variant<int, std::string> var_t;
@@ -115,7 +146,13 @@ int test_main(int , char* [])
std::sort(vec.begin(), vec.end());
std::string sort_result( print_range(vec.begin(), vec.end()) );
BOOST_CHECK( sort_result == "3 5 goodbye hello " );
BOOST_TEST( sort_result == "3 5 goodbye hello " );
return boost::exit_success;
// https://svn.boost.org/trac/boost/ticket/11751
int a = 0, b = 0;
boost::variant< int& > v (a), u (b);
BOOST_TEST(v == u);
return boost::report_errors();
}
+417
View File
@@ -0,0 +1,417 @@
//-----------------------------------------------------------------------------
// boost-libs variant/test/variant_get_test.cpp source file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2014-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifdef _MSC_VER
#pragma warning(disable: 4127) // conditional expression is constant
#pragma warning(disable: 4181) // qualifier applied to reference type; ignored
#endif
#include "boost/variant/get.hpp"
#include "boost/variant/variant.hpp"
#include "boost/variant/polymorphic_get.hpp"
#include "boost/variant/recursive_wrapper.hpp"
#include "boost/core/lightweight_test.hpp"
struct base {
int trash;
base() : trash(123) {}
base(const base& b) : trash(b.trash) { int i = 100; (void)i; }
const base& operator=(const base& b) {
trash = b.trash;
int i = 100; (void)i;
return *this;
}
virtual ~base(){}
};
struct derived1 : base{};
struct derived2 : base{};
struct vbase { short trash; virtual ~vbase(){} virtual int foo() const { return 0; } };
struct vderived1 : virtual vbase{ virtual int foo() const { return 1; } };
struct vderived2 : virtual vbase{ virtual int foo() const { return 3; } };
struct vderived3 : vderived1, vderived2 { virtual int foo() const { return 3; } };
typedef boost::variant<int, base, derived1, derived2, std::string> var_t;
typedef boost::variant<int, derived1, derived2, std::string> var_t_shortened;
typedef boost::variant<base, derived1, derived2> var_t_no_fallback;
typedef boost::variant<int&, base&, derived1&, derived2&, std::string&> var_ref_t;
typedef boost::variant<const int&, const base&, const derived1&, const derived2&, const std::string&> var_cref_t;
struct recursive_structure;
typedef boost::variant<
int, base, derived1, derived2, std::string, boost::recursive_wrapper<recursive_structure>
> var_req_t;
struct recursive_structure { var_req_t var; };
template <class TypeInVariant, class V, class TestType>
inline void check_polymorphic_get_on_types_impl_single_type(V* v)
{
typedef typename boost::add_reference<TestType>::type ref_test_t;
typedef typename boost::add_reference<const TestType>::type cref_test_t;
const bool exact_same = !!boost::is_same<TypeInVariant, TestType>::value;
const bool ref_same = !!boost::is_same<TypeInVariant, ref_test_t>::value;
if (exact_same || ref_same) {
BOOST_TEST(boost::polymorphic_get<TestType>(v));
BOOST_TEST(boost::polymorphic_get<const TestType>(v));
BOOST_TEST(boost::polymorphic_strict_get<TestType>(v));
BOOST_TEST(boost::polymorphic_strict_get<const TestType>(v));
BOOST_TEST(boost::polymorphic_relaxed_get<TestType>(v));
BOOST_TEST(boost::polymorphic_relaxed_get<const TestType>(v));
BOOST_TEST(boost::polymorphic_get<cref_test_t>(v));
BOOST_TEST(boost::polymorphic_strict_get<cref_test_t>(v));
BOOST_TEST(boost::polymorphic_relaxed_get<cref_test_t>(v));
if (ref_same) {
BOOST_TEST(boost::polymorphic_get<ref_test_t>(v));
BOOST_TEST(boost::polymorphic_get<cref_test_t>(v));
BOOST_TEST(boost::polymorphic_strict_get<ref_test_t>(v));
BOOST_TEST(boost::polymorphic_strict_get<cref_test_t>(v));
BOOST_TEST(boost::polymorphic_relaxed_get<ref_test_t>(v));
BOOST_TEST(boost::polymorphic_relaxed_get<cref_test_t>(v));
}
} else {
BOOST_TEST(!boost::polymorphic_get<TestType>(v));
BOOST_TEST(!boost::polymorphic_get<const TestType>(v));
BOOST_TEST(!boost::polymorphic_strict_get<TestType>(v));
BOOST_TEST(!boost::polymorphic_strict_get<const TestType>(v));
BOOST_TEST(!boost::polymorphic_relaxed_get<TestType>(v));
BOOST_TEST(!boost::polymorphic_relaxed_get<const TestType>(v));
}
}
template <class T, class V, class TestType>
inline void check_get_on_types_impl_single_type(V* v)
{
typedef typename boost::add_reference<TestType>::type ref_test_t;
typedef typename boost::add_reference<const TestType>::type cref_test_t;
const bool exact_same = !!boost::is_same<T, TestType>::value;
const bool ref_same = !!boost::is_same<T, ref_test_t>::value;
if (exact_same || ref_same) {
BOOST_TEST(boost::get<TestType>(v));
BOOST_TEST(boost::get<const TestType>(v));
BOOST_TEST(boost::strict_get<TestType>(v));
BOOST_TEST(boost::strict_get<const TestType>(v));
BOOST_TEST(boost::relaxed_get<TestType>(v));
BOOST_TEST(boost::relaxed_get<const TestType>(v));
BOOST_TEST(boost::get<cref_test_t>(v));
BOOST_TEST(boost::strict_get<cref_test_t>(v));
BOOST_TEST(boost::relaxed_get<cref_test_t>(v));
if (ref_same) {
BOOST_TEST(boost::get<ref_test_t>(v));
BOOST_TEST(boost::get<cref_test_t>(v));
BOOST_TEST(boost::strict_get<ref_test_t>(v));
BOOST_TEST(boost::strict_get<cref_test_t>(v));
BOOST_TEST(boost::relaxed_get<ref_test_t>(v));
BOOST_TEST(boost::relaxed_get<cref_test_t>(v));
}
} else {
BOOST_TEST(!boost::get<TestType>(v));
BOOST_TEST(!boost::get<const TestType>(v));
BOOST_TEST(!boost::strict_get<TestType>(v));
BOOST_TEST(!boost::strict_get<const TestType>(v));
BOOST_TEST(!boost::relaxed_get<TestType>(v));
BOOST_TEST(!boost::relaxed_get<const TestType>(v));
}
}
template <class T, class V>
inline void check_get_on_types_impl(V* v)
{
check_get_on_types_impl_single_type<T, V, int>(v);
check_polymorphic_get_on_types_impl_single_type<T, V, int>(v);
check_get_on_types_impl_single_type<T, V, base>(v);
check_get_on_types_impl_single_type<T, V, derived1>(v);
check_polymorphic_get_on_types_impl_single_type<T, V, derived1>(v);
check_get_on_types_impl_single_type<T, V, derived2>(v);
check_polymorphic_get_on_types_impl_single_type<T, V, derived2>(v);
check_get_on_types_impl_single_type<T, V, std::string>(v);
check_polymorphic_get_on_types_impl_single_type<T, V, std::string>(v);
// Never exist in here
BOOST_TEST(!boost::relaxed_get<short>(v));
BOOST_TEST(!boost::relaxed_get<const short>(v));
BOOST_TEST(!boost::relaxed_get<char>(v));
BOOST_TEST(!boost::relaxed_get<char*>(v));
BOOST_TEST(!boost::relaxed_get<bool>(v));
BOOST_TEST(!boost::relaxed_get<const bool>(v));
BOOST_TEST(!boost::polymorphic_relaxed_get<short>(v));
BOOST_TEST(!boost::polymorphic_relaxed_get<const short>(v));
BOOST_TEST(!boost::polymorphic_relaxed_get<char>(v));
BOOST_TEST(!boost::polymorphic_relaxed_get<char*>(v));
BOOST_TEST(!boost::polymorphic_relaxed_get<bool>(v));
BOOST_TEST(!boost::polymorphic_relaxed_get<const bool>(v));
boost::get<T>(*v); // Must compile
boost::get<const T>(*v); // Must compile
boost::strict_get<T>(*v); // Must compile
boost::strict_get<const T>(*v); // Must compile
bool is_ref = boost::is_lvalue_reference<T>::value;
(void)is_ref;
if (!is_ref) {
boost::polymorphic_get<T>(*v); // Must compile
boost::polymorphic_get<const T>(*v); // Must compile
boost::polymorphic_strict_get<T>(*v); // Must compile
boost::polymorphic_strict_get<const T>(*v); // Must compile
}
}
template <class T, class V>
inline void check_get_on_types(V* v)
{
check_get_on_types_impl<T, V>(v);
check_get_on_types_impl<T, const V>(v);
}
inline void get_test()
{
var_t v;
check_get_on_types<int>(&v);
var_t(base()).swap(v);
check_get_on_types<base>(&v);
var_t(derived1()).swap(v);
check_get_on_types<derived1>(&v);
var_t(derived2()).swap(v);
check_get_on_types<derived2>(&v);
var_t(std::string("Hello")).swap(v);
check_get_on_types<std::string>(&v);
var_t_shortened vs = derived2();
check_polymorphic_get_on_types_impl_single_type<derived2, var_t_shortened, int>(&vs);
check_polymorphic_get_on_types_impl_single_type<derived2, const var_t_shortened, int>(&vs);
// Checking that Base is really determinated
check_polymorphic_get_on_types_impl_single_type<base, var_t_shortened, base>(&vs);
check_polymorphic_get_on_types_impl_single_type<base, const var_t_shortened, base>(&vs);
vs = derived1();
check_polymorphic_get_on_types_impl_single_type<derived2, var_t_shortened, int>(&vs);
check_polymorphic_get_on_types_impl_single_type<derived2, const var_t_shortened, int>(&vs);
// Checking that Base is really determinated
check_polymorphic_get_on_types_impl_single_type<base, var_t_shortened, base>(&vs);
check_polymorphic_get_on_types_impl_single_type<base, const var_t_shortened, base>(&vs);
}
inline void get_test_no_fallback()
{
var_t_no_fallback v;
var_t_no_fallback(base()).swap(v);
check_polymorphic_get_on_types_impl_single_type<base, var_t_no_fallback, base>(&v);
check_polymorphic_get_on_types_impl_single_type<base, const var_t_no_fallback, base>(&v);
check_get_on_types_impl_single_type<base, var_t_no_fallback, base>(&v);
check_get_on_types_impl_single_type<base, const var_t_no_fallback, base>(&v);
var_t_no_fallback(derived1()).swap(v);
check_polymorphic_get_on_types_impl_single_type<base, var_t_no_fallback, base>(&v);
check_polymorphic_get_on_types_impl_single_type<base, const var_t_no_fallback, base>(&v);
check_get_on_types_impl_single_type<derived1, var_t_no_fallback, derived1>(&v);
check_get_on_types_impl_single_type<derived1, const var_t_no_fallback, derived1>(&v);
var_t_no_fallback(derived2()).swap(v);
check_polymorphic_get_on_types_impl_single_type<base, var_t_no_fallback, base>(&v);
check_polymorphic_get_on_types_impl_single_type<base, const var_t_no_fallback, base>(&v);
check_get_on_types_impl_single_type<derived2, var_t_no_fallback, derived2>(&v);
check_get_on_types_impl_single_type<derived2, const var_t_no_fallback, derived2>(&v);
}
inline void get_ref_test()
{
int i = 0;
var_ref_t v(i);
check_get_on_types<int>(&v);
check_get_on_types<int&>(&v);
base b;
var_ref_t v1(b);
check_get_on_types<base>(&v1);
check_get_on_types<base&>(&v1);
derived1 d1;
var_ref_t v2(d1);
check_get_on_types<derived1>(&v2);
check_get_on_types<derived1&>(&v2);
derived2 d2;
var_ref_t v3(d2);
check_get_on_types<derived2>(&v3);
check_get_on_types<derived2&>(&v3);
std::string s("Hello");
var_ref_t v4(s);
check_get_on_types<std::string>(&v4);
check_get_on_types<std::string&>(&v4);
}
inline void get_cref_test()
{
int i = 0;
var_cref_t v(i);
BOOST_TEST(boost::get<const int>(&v));
BOOST_TEST(boost::get<const int&>(&v));
BOOST_TEST(!boost::get<const base>(&v));
base b;
var_cref_t v1(b);
BOOST_TEST(boost::get<const base>(&v1));
BOOST_TEST(!boost::get<const derived1>(&v1));
BOOST_TEST(!boost::get<const int>(&v1));
std::string s("Hello");
const var_cref_t v4 = s;
BOOST_TEST(boost::get<const std::string>(&v4));
BOOST_TEST(!boost::get<const int>(&v4));
}
inline void get_recursive_test()
{
var_req_t v;
check_get_on_types<int>(&v);
var_req_t(base()).swap(v);
check_get_on_types<base>(&v);
var_req_t(derived1()).swap(v);
check_get_on_types<derived1>(&v);
var_req_t(derived2()).swap(v);
check_get_on_types<derived2>(&v);
var_req_t(std::string("Hello")).swap(v);
check_get_on_types<std::string>(&v);
recursive_structure s = { v }; // copying "v"
v = s;
check_get_on_types<recursive_structure>(&v);
}
template <class T>
inline void check_that_does_not_exist_impl()
{
using namespace boost::detail::variant;
BOOST_TEST((holds_element<T, const int>::value));
BOOST_TEST((!holds_element<T, short>::value));
BOOST_TEST((!holds_element<T, short>::value));
BOOST_TEST((!holds_element<T, const short>::value));
BOOST_TEST((!holds_element<T, char*>::value));
BOOST_TEST((!holds_element<T, const char*>::value));
BOOST_TEST((!holds_element<T, char[5]>::value));
BOOST_TEST((!holds_element<T, const char[5]>::value));
BOOST_TEST((!holds_element<T, bool>::value));
BOOST_TEST((!holds_element<T, const bool>::value));
BOOST_TEST((!holds_element<T, boost::recursive_wrapper<int> >::value));
BOOST_TEST((!holds_element<T, boost::recursive_wrapper<short> >::value));
BOOST_TEST((!holds_element<T, boost::detail::reference_content<short> >::value));
BOOST_TEST((holds_element_polymorphic<T, const int>::value));
BOOST_TEST((!holds_element_polymorphic<T, short>::value));
BOOST_TEST((!holds_element_polymorphic<T, short>::value));
BOOST_TEST((!holds_element_polymorphic<T, const short>::value));
BOOST_TEST((!holds_element_polymorphic<T, char*>::value));
BOOST_TEST((!holds_element_polymorphic<T, const char*>::value));
BOOST_TEST((!holds_element_polymorphic<T, char[5]>::value));
BOOST_TEST((!holds_element_polymorphic<T, const char[5]>::value));
BOOST_TEST((!holds_element_polymorphic<T, bool>::value));
BOOST_TEST((!holds_element_polymorphic<T, const bool>::value));
BOOST_TEST((!holds_element_polymorphic<T, boost::recursive_wrapper<int> >::value));
BOOST_TEST((!holds_element_polymorphic<T, boost::recursive_wrapper<short> >::value));
BOOST_TEST((!holds_element_polymorphic<T, boost::detail::reference_content<short> >::value));
}
inline void check_that_does_not_exist()
{
using namespace boost::detail::variant;
BOOST_TEST((holds_element<var_t, int>::value));
BOOST_TEST((holds_element<var_ref_t, int>::value));
BOOST_TEST((!holds_element<var_cref_t, int>::value));
check_that_does_not_exist_impl<var_t>();
check_that_does_not_exist_impl<var_ref_t>();
check_that_does_not_exist_impl<var_cref_t>();
check_that_does_not_exist_impl<var_req_t>();
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
class MoveonlyType {
public:
MoveonlyType() {}
~MoveonlyType() {}
MoveonlyType(MoveonlyType&&) {}
void operator=(MoveonlyType&&) {}
private:
MoveonlyType(const MoveonlyType&);
void operator=(const MoveonlyType&);
};
const boost::variant<int, std::string> foo1() { return ""; }
boost::variant<int, std::string> foo2() { return ""; }
inline void get_rvref_test()
{
boost::get<std::string>(foo1());
boost::get<std::string>(foo2());
boost::variant<MoveonlyType, int> v;
v = MoveonlyType();
boost::get<MoveonlyType>(std::move(v));
v = 3;
v = MoveonlyType();
boost::get<MoveonlyType>(v);
boost::relaxed_get<MoveonlyType&>(boost::variant<MoveonlyType, int>());
v = MoveonlyType();
MoveonlyType moved_from_variant(boost::get<MoveonlyType>(std::move(v)));
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
int main()
{
get_test();
get_test_no_fallback();
get_ref_test();
get_cref_test();
get_recursive_test();
check_that_does_not_exist();
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
get_rvref_test();
#endif
return boost::report_errors();
}
+76 -44
View File
@@ -3,64 +3,88 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2013
// Antony Polukhin
// Copyright (c) 2013-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "boost/config.hpp"
#include "boost/noncopyable.hpp"
#define BOOST_VARAINT_MAX_MULTIVIZITOR_PARAMS 5
#include "boost/variant/multivisitors.hpp"
#include "boost/variant.hpp"
#include "boost/test/minimal.hpp"
#include "boost/core/lightweight_test.hpp"
typedef boost::variant<char, unsigned char, signed char, unsigned short, int, unsigned int> variant6_t;
struct my_noncopyable : boost::noncopyable {
my_noncopyable(){}
~my_noncopyable(){}
};
typedef boost::variant<my_noncopyable, int> variant_noncopy_t;
typedef boost::variant<char, unsigned char, signed char, unsigned short, int> variant5_t;
struct test_visitor: boost::static_visitor<> {
// operators that shall not be called
template <class T1, class T2, class T3>
void operator()(T1, T2, T3) const
void operator()(T1&, T2&, T3&) const
{
BOOST_CHECK(false);
BOOST_TEST(false);
}
template <class T1, class T2, class T3, class T4>
void operator()(T1, T2, T3, T4) const
void operator()(T1&, T2&, T3&, T4&) const
{
BOOST_CHECK(false);
BOOST_TEST(false);
}
template <class T1, class T2, class T3, class T4, class T5>
void operator()(T1, T2, T3, T4, T5) const
void operator()(T1&, T2&, T3&, T4&, T5&) const
{
BOOST_CHECK(false);
BOOST_TEST(false);
}
// operators that are OK to call
void operator()(char v0, unsigned char v1, signed char v2) const
{
BOOST_CHECK(v0 == 0);
BOOST_CHECK(v1 == 1);
BOOST_CHECK(v2 == 2);
BOOST_TEST(v0 == 0);
BOOST_TEST(v1 == 1);
BOOST_TEST(v2 == 2);
}
void operator()(char v0, unsigned char v1, signed char v2, unsigned short v3) const
{
BOOST_CHECK(v0 == 0);
BOOST_CHECK(v1 == 1);
BOOST_CHECK(v2 == 2);
BOOST_CHECK(v3 == 3);
BOOST_TEST(v0 == 0);
BOOST_TEST(v1 == 1);
BOOST_TEST(v2 == 2);
BOOST_TEST(v3 == 3);
}
void operator()(char v0, unsigned char v1, signed char v2, unsigned short v3, int v4) const
{
BOOST_CHECK(v0 == 0);
BOOST_CHECK(v1 == 1);
BOOST_CHECK(v2 == 2);
BOOST_CHECK(v3 == 3);
BOOST_CHECK(v4 == 4);
BOOST_TEST(v0 == 0);
BOOST_TEST(v1 == 1);
BOOST_TEST(v2 == 2);
BOOST_TEST(v3 == 3);
BOOST_TEST(v4 == 4);
}
// Noncopyables
void operator()(my_noncopyable&, my_noncopyable&, my_noncopyable&) const {
BOOST_TEST(true);
}
void operator()(my_noncopyable&, my_noncopyable&, my_noncopyable&, my_noncopyable&) const {
BOOST_TEST(true);
}
void operator()(my_noncopyable&, my_noncopyable&, my_noncopyable&, my_noncopyable&, my_noncopyable&) const {
BOOST_TEST(true);
}
void operator()(my_noncopyable&, my_noncopyable&, my_noncopyable&, my_noncopyable&, my_noncopyable&, my_noncopyable&) const {
BOOST_TEST(true);
}
};
@@ -68,9 +92,9 @@ typedef boost::variant<int, double, bool> bool_like_t;
typedef boost::variant<int, double> arithmetics_t;
struct if_visitor: public boost::static_visitor<arithmetics_t> {
template <class T1, class T2>
arithmetics_t operator()(bool b, T1 v1, T2 v2) const {
if (b) {
template <class T0, class T1, class T2>
arithmetics_t operator()(T0 b, T1 v1, T2 v2) const {
if (!!b) {
return v1;
} else {
return v2;
@@ -79,46 +103,54 @@ struct if_visitor: public boost::static_visitor<arithmetics_t> {
};
int test_main(int , char* [])
int main()
{
test_visitor v;
variant6_t v_array6[6];
v_array6[0] = char(0);
v_array6[1] = static_cast<unsigned char>(1);
v_array6[2] = static_cast<signed char>(2);
v_array6[3] = static_cast<unsigned short>(3);
v_array6[4] = static_cast<int>(4);
v_array6[5] = static_cast<unsigned int>(5);
variant5_t v_array5[5];
v_array5[0] = char(0);
v_array5[1] = static_cast<unsigned char>(1);
v_array5[2] = static_cast<signed char>(2);
v_array5[3] = static_cast<unsigned short>(3);
v_array5[4] = static_cast<int>(4);
boost::apply_visitor(v, v_array6[0], v_array6[1], v_array6[2]);
boost::apply_visitor(test_visitor(), v_array6[0], v_array6[1], v_array6[2]);
boost::apply_visitor(v, v_array5[0], v_array5[1], v_array5[2]);
boost::apply_visitor(test_visitor(), v_array5[0], v_array5[1], v_array5[2]);
// Following test also pass, but requires many Gigabytes of RAM for compilation and compile for about 15 minutes
//#define BOOST_VARIANT_MULTIVISITORS_TEST_VERY_EXTREME
#ifdef BOOST_VARIANT_MULTIVISITORS_TEST_VERY_EXTREME
boost::apply_visitor(v, v_array6[0], v_array6[1], v_array6[2], v_array6[3]);
boost::apply_visitor(test_visitor(), v_array6[0], v_array6[1], v_array6[2], v_array6[3]);
boost::apply_visitor(v, v_array5[0], v_array5[1], v_array5[2], v_array5[3]);
boost::apply_visitor(test_visitor(), v_array5[0], v_array5[1], v_array5[2], v_array5[3]);
boost::apply_visitor(v, v_array6[0], v_array6[1], v_array6[2], v_array6[3], v_array6[4]);
boost::apply_visitor(test_visitor(), v_array6[0], v_array6[1], v_array6[2], v_array6[3], v_array6[4]);
boost::apply_visitor(v, v_array5[0], v_array5[1], v_array5[2], v_array5[3], v_array5[4]);
boost::apply_visitor(test_visitor(), v_array5[0], v_array5[1], v_array5[2], v_array5[3], v_array5[4]);
#endif
bool_like_t v0(1), v1(true), v2(1.0);
BOOST_CHECK(
BOOST_TEST(
boost::apply_visitor(if_visitor(), v0, v1, v2)
==
arithmetics_t(true)
);
/* Delayed multi visitation is not implemented
if_visitor if_vis;
BOOST_CHECK(
BOOST_TEST(
boost::apply_visitor(if_vis)(v0, v1, v2)
==
arithmetics_t(true)
);
*/
return boost::exit_success;
variant_noncopy_t vnonc[6];
boost::apply_visitor(v, vnonc[0], vnonc[1], vnonc[2]);
boost::apply_visitor(test_visitor(), vnonc[0], vnonc[1], vnonc[2], vnonc[3]);
#ifdef BOOST_VARIANT_MULTIVISITORS_TEST_VERY_EXTREME
boost::apply_visitor(v, vnonc[0], vnonc[1], vnonc[2], vnonc[3], vnonc[4]);
boost::apply_visitor(test_visitor(), vnonc[0], vnonc[1], vnonc[2], vnonc[3], vnonc[4], vnonc[5]);
#endif
return boost::report_errors();
}
+474
View File
@@ -0,0 +1,474 @@
//-----------------------------------------------------------------------------
// boost-libs variant/test/variant_nonempty_check.cpp source file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2014-2026 Antony Polukhin
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// In this file we are making tests to ensure that variant guarantees nonemptiness.
//
// For that purpose we create a `throwing_class`, that throws exception at a specified
// assignment attempt. If exception was thrown during move/assignemnt operation we make sure
// that data in variant is same as before move/assignemnt operation or that a fallback type is
// stored in variant.
//
// Different nonthrowing_class'es are used to tests different variant internal policies:
// with/without fallback type + throw/nothrow copyable + throw/nothrow movable
#include "boost/variant/variant.hpp"
#include "boost/variant/get.hpp"
#include "boost/core/lightweight_test.hpp"
#include <stdexcept>
struct exception_on_assignment : std::exception {};
struct exception_on_move_assignment : exception_on_assignment {};
void prevent_compiler_noexcept_detection() {
char* p = new char;
*p = '\0';
delete p;
}
struct throwing_class {
int trash;
enum helper_enum {
do_not_throw = 780,
throw_after_5,
throw_after_4,
throw_after_3,
throw_after_2,
throw_after_1
};
bool is_throw() {
if (trash < do_not_throw) {
return true;
}
if (trash > do_not_throw && trash <= throw_after_1) {
++ trash;
return false;
}
return trash != do_not_throw;
}
throwing_class(int value = 123) BOOST_NOEXCEPT_IF(false) : trash(value) {
prevent_compiler_noexcept_detection();
}
throwing_class(const throwing_class& b) BOOST_NOEXCEPT_IF(false) : trash(b.trash) {
if (is_throw()) {
throw exception_on_assignment();
}
}
const throwing_class& operator=(const throwing_class& b) BOOST_NOEXCEPT_IF(false) {
trash = b.trash;
if (is_throw()) {
throw exception_on_assignment();
}
return *this;
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
throwing_class(throwing_class&& b) BOOST_NOEXCEPT_IF(false) : trash(b.trash) {
if (is_throw()) {
throw exception_on_move_assignment();
}
}
const throwing_class& operator=(throwing_class&& b) BOOST_NOEXCEPT_IF(false) {
trash = b.trash;
if (is_throw()) {
throw exception_on_move_assignment();
}
return *this;
}
#endif
virtual ~throwing_class() {}
};
struct nonthrowing_class {
int trash;
nonthrowing_class() BOOST_NOEXCEPT_IF(false) : trash(123) {
prevent_compiler_noexcept_detection();
}
nonthrowing_class(const nonthrowing_class&) BOOST_NOEXCEPT_IF(false) {
prevent_compiler_noexcept_detection();
}
const nonthrowing_class& operator=(const nonthrowing_class&) BOOST_NOEXCEPT_IF(false) {
prevent_compiler_noexcept_detection();
return *this;
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
nonthrowing_class(nonthrowing_class&&) BOOST_NOEXCEPT_IF(false) {
prevent_compiler_noexcept_detection();
}
const nonthrowing_class& operator=(nonthrowing_class&&) BOOST_NOEXCEPT_IF(false) {
prevent_compiler_noexcept_detection();
return *this;
}
#endif
};
struct nonthrowing_class2 {
int trash;
nonthrowing_class2() BOOST_NOEXCEPT_IF(false) : trash(123) {
prevent_compiler_noexcept_detection();
}
};
struct nonthrowing_class3 {
int trash;
nonthrowing_class3() BOOST_NOEXCEPT_IF(true) : trash(123) {}
nonthrowing_class3(const nonthrowing_class3&) BOOST_NOEXCEPT_IF(false) {
prevent_compiler_noexcept_detection();
}
const nonthrowing_class3& operator=(const nonthrowing_class3&) BOOST_NOEXCEPT_IF(false) {
prevent_compiler_noexcept_detection();
return *this;
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
nonthrowing_class3(nonthrowing_class3&&) BOOST_NOEXCEPT_IF(false) {
prevent_compiler_noexcept_detection();
}
const nonthrowing_class3& operator=(nonthrowing_class3&&) BOOST_NOEXCEPT_IF(false) {
prevent_compiler_noexcept_detection();
return *this;
}
#endif
};
struct nonthrowing_class4 {
int trash;
nonthrowing_class4() BOOST_NOEXCEPT_IF(false) : trash(123) {
prevent_compiler_noexcept_detection();
}
nonthrowing_class4(const nonthrowing_class4&) BOOST_NOEXCEPT_IF(false) {
prevent_compiler_noexcept_detection();
}
const nonthrowing_class4& operator=(const nonthrowing_class4&) BOOST_NOEXCEPT_IF(false) {
prevent_compiler_noexcept_detection();
return *this;
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
nonthrowing_class4(nonthrowing_class4&&) BOOST_NOEXCEPT_IF(true) {
}
const nonthrowing_class4& operator=(nonthrowing_class4&&) BOOST_NOEXCEPT_IF(true) {
return *this;
}
#endif
};
// Tests /////////////////////////////////////////////////////////////////////////////////////
template <class Nonthrowing>
inline void check_1_impl(int helper)
{
boost::variant<throwing_class, Nonthrowing> v;
try {
v = throwing_class(helper);
BOOST_TEST(!v.which());
BOOST_TEST(boost::get<throwing_class>(&v));
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(!v.which());
BOOST_TEST(boost::get<throwing_class>(&v));
}
try {
throwing_class tc(helper);
v = tc;
BOOST_TEST(!v.which());
BOOST_TEST(boost::get<throwing_class>(&v));
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(!v.which());
BOOST_TEST(boost::get<throwing_class>(&v));
}
}
inline void check_1(int helper = 1)
{
check_1_impl<nonthrowing_class>(helper);
check_1_impl<nonthrowing_class2>(helper);
check_1_impl<nonthrowing_class3>(helper);
check_1_impl<nonthrowing_class4>(helper);
check_1_impl<boost::blank>(helper);
}
template <class Nonthrowing>
inline void check_2_impl(int helper)
{
boost::variant<Nonthrowing, throwing_class> v;
try {
v = throwing_class(helper);
BOOST_TEST(v.which() == 1);
BOOST_TEST(boost::get<throwing_class>(&v));
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(!v.which());
BOOST_TEST(boost::get<Nonthrowing>(&v));
}
try {
throwing_class cl(helper);
v = cl;
BOOST_TEST(v.which() == 1);
BOOST_TEST(boost::get<throwing_class>(&v));
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(!v.which());
BOOST_TEST(boost::get<Nonthrowing>(&v));
}
}
inline void check_2(int helper = 1)
{
check_2_impl<nonthrowing_class>(helper);
check_2_impl<nonthrowing_class2>(helper);
check_2_impl<nonthrowing_class3>(helper);
check_2_impl<nonthrowing_class4>(helper);
check_2_impl<boost::blank>(helper);
}
template <class Nonthrowing>
inline void check_3_impl(int helper)
{
boost::variant<Nonthrowing, throwing_class> v1, v2;
swap(v1, v2);
try {
v1 = throwing_class(helper);
BOOST_TEST(v1.which() == 1);
BOOST_TEST(boost::get<throwing_class>(&v1));
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(!v1.which());
BOOST_TEST(boost::get<Nonthrowing>(&v1));
}
try {
v2 = throwing_class(helper);
BOOST_TEST(v2.which() == 1);
BOOST_TEST(boost::get<throwing_class>(&v2));
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(!v2.which());
BOOST_TEST(boost::get<Nonthrowing>(&v2));
}
if (!v1.which() && !v2.which()) {
swap(v1, v2); // Make sure that two backup holders swap well
BOOST_TEST(!v1.which());
BOOST_TEST(boost::get<Nonthrowing>(&v1));
BOOST_TEST(!v2.which());
BOOST_TEST(boost::get<Nonthrowing>(&v2));
v1 = v2;
}
}
inline void check_3(int helper = 1)
{
check_3_impl<nonthrowing_class>(helper);
check_3_impl<nonthrowing_class2>(helper);
check_3_impl<nonthrowing_class3>(helper);
check_3_impl<nonthrowing_class4>(helper);
check_3_impl<boost::blank>(helper);
}
inline void check_4(int helper = 1)
{
// This one has a fallback
boost::variant<int, throwing_class> v1, v2;
swap(v1, v2);
try {
v1 = throwing_class(helper);
BOOST_TEST(v1.which() == 1);
BOOST_TEST(boost::get<throwing_class>(&v1));
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(!v1.which());
BOOST_TEST(boost::get<int>(&v1));
}
try {
v2 = throwing_class(helper);
BOOST_TEST(v2.which() == 1);
BOOST_TEST(boost::get<throwing_class>(&v2));
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(!v2.which());
BOOST_TEST(boost::get<int>(&v2));
}
if (!v1.which() && !v2.which()) {
swap(v1, v2);
BOOST_TEST(!v1.which());
BOOST_TEST(boost::get<int>(&v1));
BOOST_TEST(!v2.which());
BOOST_TEST(boost::get<int>(&v2));
v1 = v2;
}
}
template <class Nonthrowing>
inline void check_5_impl(int helper)
{
boost::variant<Nonthrowing, throwing_class> v1, v2;
throwing_class throw_not_now;
throw_not_now.trash = throwing_class::do_not_throw;
v1 = throw_not_now;
v2 = throw_not_now;
boost::get<throwing_class>(v1).trash = 1;
boost::get<throwing_class>(v2).trash = 1;
try {
v1 = throwing_class(helper);
BOOST_TEST(v1.which() == 1);
BOOST_TEST(boost::get<throwing_class>(&v1));
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(v1.which() == 1);
BOOST_TEST(boost::get<throwing_class>(&v1));
}
boost::get<throwing_class>(v1).trash = throwing_class::do_not_throw;
boost::get<throwing_class>(v2).trash = throwing_class::do_not_throw;
v1 = Nonthrowing();
v2 = Nonthrowing();
try {
v1 = throwing_class(helper);
BOOST_TEST(v1.which() == 1);
BOOST_TEST(boost::get<throwing_class>(&v1));
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(v1.which() == 0);
BOOST_TEST(boost::get<Nonthrowing>(&v1));
}
int v1_type = v1.which();
int v2_type = v2.which();
try {
swap(v1, v2); // Make sure that backup holders swap well
BOOST_TEST(v1.which() == v2_type);
BOOST_TEST(v2.which() == v1_type);
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(v1.which() == v1_type);
BOOST_TEST(v2.which() == v2_type);
}
}
inline void check_5(int helper = 1)
{
check_5_impl<nonthrowing_class>(helper);
check_5_impl<nonthrowing_class2>(helper);
check_5_impl<nonthrowing_class3>(helper);
check_5_impl<nonthrowing_class4>(helper);
check_5_impl<boost::blank>(helper);
}
template <class Nonthrowing>
inline void check_6_impl(int helper)
{
boost::variant<Nonthrowing, throwing_class> v1, v2;
throwing_class throw_not_now;
throw_not_now.trash = throwing_class::do_not_throw;
v1 = throw_not_now;
v2 = throw_not_now;
v1 = throw_not_now;
v2 = throw_not_now;
swap(v1, v2);
boost::get<throwing_class>(v1).trash = 1;
boost::get<throwing_class>(v2).trash = 1;
v1 = throwing_class(throw_not_now);
v2 = v1;
v1 = Nonthrowing();
try {
throwing_class tc;
tc.trash = helper;
v1 = tc;
BOOST_TEST(v1.which() == 1);
BOOST_TEST(boost::get<throwing_class>(&v1));
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(v1.which() == 0);
}
v2 = Nonthrowing();
try {
v2 = 2;
BOOST_TEST(false);
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(v2.which() == 0);
}
// Probably the most significant test:
// unsuccessful swap must preserve old values of variant
v1 = throw_not_now;
boost::get<throwing_class>(v1).trash = helper;
try {
swap(v1, v2);
} catch (const exception_on_assignment& /*e*/) {
BOOST_TEST(v1.which() == 1);
BOOST_TEST(v2.which() == 0);
BOOST_TEST(boost::get<throwing_class>(v1).trash == helper);
}
}
inline void check_6(int helper = 1)
{
check_6_impl<nonthrowing_class>(helper);
check_6_impl<nonthrowing_class2>(helper);
check_6_impl<nonthrowing_class3>(helper);
check_6_impl<nonthrowing_class4>(helper);
check_6_impl<boost::blank>(helper);
}
int main()
{
// throwing_class::throw_after_1 + 1 => throw on first assignment/construction
// throwing_class::throw_after_1 => throw on second assignment/construction
// throwing_class::throw_after_2 => throw on third assignment/construction
// ...
for (int i = throwing_class::throw_after_1 + 1; i != throwing_class::do_not_throw; --i) {
check_1(i);
check_2(i);
check_3(i);
check_4(i);
check_5(i);
check_6(i);
}
return boost::report_errors();
}
+64
View File
@@ -0,0 +1,64 @@
// Copyright (c) 2017
// Mikhail Maximov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// The test is base on https://svn.boost.org/trac/boost/ticket/8554
// variant was not able to extract types from mpl::joint_view
#include <string>
#include "boost/config.hpp"
#include "boost/core/lightweight_test.hpp"
#include "boost/variant.hpp"
#include "boost/mpl/joint_view.hpp"
#include "boost/mpl/insert_range.hpp"
#include "boost/mpl/set.hpp"
template<class T, class Variant>
void check_exception_on_get(Variant& v) {
try {
boost::get<T>(v);
BOOST_ERROR("Expected exception boost::bad_get, but got nothing.");
} catch (boost::bad_get&) { //okay it is expected behaviour
} catch (...) { BOOST_ERROR("Expected exception boost::bad_get, but got something else."); }
}
void test_joint_view() {
typedef boost::variant<int> v1;
typedef boost::variant<std::string> v2;
typedef boost::make_variant_over<boost::mpl::joint_view<v1::types, v2::types>::type>::type v3;
v1 a = 1;
v2 b = "2";
v3 c = a;
BOOST_TEST(boost::get<int>(c) == 1);
BOOST_TEST(c.which() == 0);
v3 d = b;
BOOST_TEST(boost::get<std::string>(d) == "2");
BOOST_TEST(d.which() == 1);
check_exception_on_get<std::string>(c);
check_exception_on_get<int>(d);
}
void test_set() {
typedef boost::mpl::set2< std::string, int > types;
typedef boost::make_variant_over< types >::type v;
v a = 1;
BOOST_TEST(boost::get<int>(a) == 1);
check_exception_on_get<std::string>(a);
a = "2";
BOOST_TEST(boost::get<std::string>(a) == "2");
check_exception_on_get<int>(a);
}
int main()
{
test_joint_view();
test_set();
return boost::report_errors();
}

Some files were not shown because too many files have changed in this diff Show More