From 0d3d8de014f1012dd0b2c2c077099cf6face44e5 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Fri, 2 Dec 2016 23:00:05 +0000 Subject: [PATCH] Implement C++17 . Patch from Michael Park! This patch was reviewed as https://reviews.llvm.org/D23263. llvm-svn: 288547 --- libcxx/include/variant | 1553 ++++++++++++++++++++ libcxx/src/variant.cpp | 18 + .../variant.variant/variant.assign/copy.pass.cpp | 181 +++ .../variant.variant/variant.assign/move.pass.cpp | 167 +++ .../variant.variant/variant.ctor/copy.pass.cpp | 120 ++ .../variant.variant/variant.ctor/move.pass.cpp | 153 ++ .../test/libcxx/utilities/variant/version.pass.cpp | 20 + libcxx/test/std/utilities/variant/lit.local.cfg | 5 - .../variant/variant.get/get_if_index.pass.cpp | 12 +- .../variant/variant.get/get_if_type.pass.cpp | 22 +- .../variant/variant.get/get_index.pass.cpp | 28 +- .../variant/variant.get/get_type.pass.cpp | 40 +- .../variant/variant.get/holds_alternative.pass.cpp | 3 +- .../utilities/variant/variant.hash/hash.pass.cpp | 3 +- .../variant.helpers/variant_alternative.pass.cpp | 4 +- .../variant.monostate.relops/relops.pass.cpp | 13 +- .../variant/variant.relops/relops.pass.cpp | 14 +- .../variant.variant/variant.assign/T.pass.cpp | 6 +- .../variant.variant/variant.assign/copy.pass.cpp | 46 +- .../variant.variant/variant.assign/move.pass.cpp | 20 +- .../variant.variant/variant.ctor/T.pass.cpp | 6 +- .../variant.variant/variant.ctor/copy.pass.cpp | 14 +- .../variant.variant/variant.ctor/default.pass.cpp | 2 +- .../variant.variant/variant.ctor/move.pass.cpp | 10 +- .../variant.variant/variant.dtor/dtor.pass.cpp | 2 +- .../variant.mod/emplace_index_args.pass.cpp | 10 +- .../variant.mod/emplace_type_args.pass.cpp | 26 +- .../variant.variant/variant.swap/swap.pass.cpp | 12 +- .../variant.variant/variant_reference.fail.cpp | 2 +- .../utilities/variant/variant.visit/visit.pass.cpp | 26 +- 30 files changed, 2374 insertions(+), 164 deletions(-) create mode 100644 libcxx/include/variant create mode 100644 libcxx/src/variant.cpp create mode 100644 libcxx/test/libcxx/utilities/variant/variant.variant/variant.assign/copy.pass.cpp create mode 100644 libcxx/test/libcxx/utilities/variant/variant.variant/variant.assign/move.pass.cpp create mode 100644 libcxx/test/libcxx/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp create mode 100644 libcxx/test/libcxx/utilities/variant/variant.variant/variant.ctor/move.pass.cpp create mode 100644 libcxx/test/libcxx/utilities/variant/version.pass.cpp delete mode 100644 libcxx/test/std/utilities/variant/lit.local.cfg diff --git a/libcxx/include/variant b/libcxx/include/variant new file mode 100644 index 0000000..f57d5ce2 --- /dev/null +++ b/libcxx/include/variant @@ -0,0 +1,1553 @@ +// -*- C++ -*- +//===------------------------------ variant -------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_VARIANT +#define _LIBCPP_VARIANT + +/* + variant synopsis + +namespace std { + + // 20.7.2, class template variant + template + class variant { + public: + + // 20.7.2.1, constructors + constexpr variant() noexcept(see below); + variant(const variant&); + variant(variant&&) noexcept(see below); + + template constexpr variant(T&&) noexcept(see below); + + template + constexpr explicit variant(in_place_type_t, Args&&...); + + template + constexpr explicit variant( + in_place_type_t, initializer_list, Args&&...); + + template + constexpr explicit variant(in_place_index_t, Args&&...); + + template + constexpr explicit variant( + in_place_index_t, initializer_list, Args&&...); + + // 20.7.2.2, destructor + ~variant(); + + // 20.7.2.3, assignment + variant& operator=(const variant&); + variant& operator=(variant&&) noexcept(see below); + + template variant& operator=(T&&) noexcept(see below); + + // 20.7.2.4, modifiers + template + void emplace(Args&&...); + + template + void emplace(initializer_list, Args&&...); + + template + void emplace(Args&&...); + + template + void emplace(initializer_list, Args&&...); + + // 20.7.2.5, value status + constexpr bool valueless_by_exception() const noexcept; + constexpr size_t index() const noexcept; + + // 20.7.2.6, swap + void swap(variant&) noexcept(see below); + }; + + // 20.7.3, variant helper classes + template struct variant_size; // undefined + + template + constexpr size_t variant_size_v = variant_size::value; + + template struct variant_size; + template struct variant_size; + template struct variant_size; + + template + struct variant_size>; + + template struct variant_alternative; // undefined + + template + using variant_alternative_t = typename variant_alternative::type; + + template struct variant_alternative; + template struct variant_alternative; + template struct variant_alternative; + + template + struct variant_alternative>; + + constexpr size_t variant_npos = -1; + + // 20.7.4, value access + template + constexpr bool holds_alternative(const variant&) noexcept; + + template + constexpr variant_alternative_t>& + get(variant&); + + template + constexpr variant_alternative_t>&& + get(variant&&); + + template + constexpr variant_alternative_t> const& + get(const variant&); + + template + constexpr variant_alternative_t> const&& + get(const variant&&); + + template + constexpr T& get(variant&); + + template + constexpr T&& get(variant&&); + + template + constexpr const T& get(const variant&); + + template + constexpr const T&& get(const variant&&); + + template + constexpr add_pointer_t>> + get_if(variant*) noexcept; + + template + constexpr add_pointer_t>> + get_if(const variant*) noexcept; + + template + constexpr add_pointer_t + get_if(variant*) noexcept; + + template + constexpr add_pointer_t + get_if(const variant*) noexcept; + + // 20.7.5, relational operators + template + constexpr bool operator==(const variant&, const variant&); + + template + constexpr bool operator!=(const variant&, const variant&); + + template + constexpr bool operator<(const variant&, const variant&); + + template + constexpr bool operator>(const variant&, const variant&); + + template + constexpr bool operator<=(const variant&, const variant&); + + template + constexpr bool operator>=(const variant&, const variant&); + + // 20.7.6, visitation + template + constexpr see below visit(Visitor&&, Variants&&...); + + // 20.7.7, class monostate + struct monostate; + + // 20.7.8, monostate relational operators + constexpr bool operator<(monostate, monostate) noexcept; + constexpr bool operator>(monostate, monostate) noexcept; + constexpr bool operator<=(monostate, monostate) noexcept; + constexpr bool operator>=(monostate, monostate) noexcept; + constexpr bool operator==(monostate, monostate) noexcept; + constexpr bool operator!=(monostate, monostate) noexcept; + + // 20.7.9, specialized algorithms + template + void swap(variant&, variant&) noexcept(see below); + + // 20.7.10, class bad_variant_access + class bad_variant_access; + + // 20.7.11, hash support + template struct hash; + template struct hash>; + template <> struct hash; + +} // namespace std + +*/ + +#include <__config> +#include <__tuple> +#include +#include +#include +#include +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +namespace std { // explicitly not using versioning namespace + +class _LIBCPP_EXCEPTION_ABI bad_variant_access : public exception { +public: + _LIBCPP_FUNC_VIS virtual const char* what() const noexcept; +}; + +} // namespace std + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +template +class _LIBCPP_TYPE_VIS_ONLY variant; + +template +struct _LIBCPP_TYPE_VIS_ONLY variant_size; + +template +constexpr size_t variant_size_v = variant_size<_Tp>::value; + +template +struct _LIBCPP_TYPE_VIS_ONLY variant_size : variant_size<_Tp> {}; + +template +struct _LIBCPP_TYPE_VIS_ONLY variant_size : variant_size<_Tp> {}; + +template +struct _LIBCPP_TYPE_VIS_ONLY variant_size + : variant_size<_Tp> {}; + +template +struct _LIBCPP_TYPE_VIS_ONLY variant_size> + : integral_constant {}; + +template +struct _LIBCPP_TYPE_VIS_ONLY variant_alternative; + +template +using variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type; + +template +struct _LIBCPP_TYPE_VIS_ONLY variant_alternative<_Ip, const _Tp> + : add_const> {}; + +template +struct _LIBCPP_TYPE_VIS_ONLY variant_alternative<_Ip, volatile _Tp> + : add_volatile> {}; + +template +struct _LIBCPP_TYPE_VIS_ONLY variant_alternative<_Ip, const volatile _Tp> + : add_cv> {}; + +template +struct _LIBCPP_TYPE_VIS_ONLY variant_alternative<_Ip, variant<_Types...>> { + static_assert(_Ip < sizeof...(_Types)); + using type = __type_pack_element<_Ip, _Types...>; +}; + +constexpr size_t variant_npos = static_cast(-1); +constexpr unsigned int __variant_npos = static_cast(-1); + +namespace __find_detail { + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr size_t __find_index() { + constexpr bool __matches[] = {is_same_v<_Tp, _Types>...}; + size_t __result = __not_found; + for (size_t __i = 0; __i < sizeof...(_Types); ++__i) { + if (__matches[__i]) { + if (__result != __not_found) { + return __ambiguous; + } + __result = __i; + } + } + return __result; +} + +template +struct __find_unambiguous_index_sfinae_impl + : integral_constant {}; + +template <> +struct __find_unambiguous_index_sfinae_impl<__not_found> {}; + +template <> +struct __find_unambiguous_index_sfinae_impl<__ambiguous> {}; + +template +struct __find_unambiguous_index_sfinae + : __find_unambiguous_index_sfinae_impl<__find_index<_Tp, _Types...>()> {}; + +} // namespace __find_detail + +namespace __variant_detail { + +struct __valueless_t {}; + +enum class _Trait { _TriviallyAvailable, _Available, _Unavailable }; + +template class _IsTriviallyAvailable, + template class _IsAvailable> +constexpr _Trait __trait = + _IsTriviallyAvailable<_Tp>::value + ? _Trait::_TriviallyAvailable + : _IsAvailable<_Tp>::value ? _Trait::_Available : _Trait::_Unavailable; + +inline _LIBCPP_INLINE_VISIBILITY +constexpr _Trait __common_trait(initializer_list<_Trait> __traits) { + _Trait __result = _Trait::_TriviallyAvailable; + for (_Trait __t : __traits) { + if (static_cast(__t) > static_cast(__result)) { + __result = __t; + } + } + return __result; +} + +template +struct __traits { + static constexpr _Trait __copy_constructible_trait = + __common_trait({__trait<_Types, + is_trivially_copy_constructible, + is_copy_constructible>...}); + + static constexpr _Trait __move_constructible_trait = + __common_trait({__trait<_Types, + is_trivially_move_constructible, + is_move_constructible>...}); + + static constexpr _Trait __copy_assignable_trait = __common_trait( + {__copy_constructible_trait, + __move_constructible_trait, + __trait<_Types, is_trivially_copy_assignable, is_copy_assignable>...}); + + static constexpr _Trait __move_assignable_trait = __common_trait( + {__move_constructible_trait, + __trait<_Types, is_trivially_move_assignable, is_move_assignable>...}); + + static constexpr _Trait __destructible_trait = __common_trait( + {__trait<_Types, is_trivially_destructible, is_destructible>...}); +}; + +namespace __access { + +struct __union { + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<0>) { + return _VSTD::forward<_Vp>(__v).__head; + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<_Ip>) { + return __get_alt(_VSTD::forward<_Vp>(__v).__tail, in_place_index<_Ip - 1>); + } +}; + +struct __base { + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __get_alt(_Vp&& __v) { + return __union::__get_alt(_VSTD::forward<_Vp>(__v).__data, + in_place_index<_Ip>); + } +}; + +struct __variant { + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __get_alt(_Vp&& __v) { + return __base::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v).__impl); + } +}; + +} // namespace __access + +namespace __visitation { + +struct __base { + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) + __visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) { + constexpr auto __fdiagonal = + __make_fdiagonal<_Visitor&&, + decltype(_VSTD::forward<_Vs>(__vs).__as_base())...>(); + return __fdiagonal[__index](_VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs).__as_base()...); + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor, + _Vs&&... __vs) { + constexpr auto __fmatrix = + __make_fmatrix<_Visitor&&, + decltype(_VSTD::forward<_Vs>(__vs).__as_base())...>(); + const size_t __indices[] = {__vs.index()...}; + return __at(__fmatrix, __indices)(_VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs).__as_base()...); + } + +private: + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr const _Tp& __at_impl(const _Tp& __elem, const size_t*) { + return __elem; + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __at_impl(const array<_Tp, _Np>& __elems, + const size_t* __index) { + return __at_impl(__elems[*__index], __index + 1); + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto&& __at(const array<_Tp, _Np>& __elems, + const size_t (&__indices)[_Ip]) { + return __at_impl(__elems, begin(__indices)); + } + + template + static constexpr void __std_visit_visitor_return_type_check() { + static_assert( + __all...>::value, + "`std::visit` requires the visitor to have a single return type."); + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_farray(_Fs&&... __fs) { + __std_visit_visitor_return_type_check...>(); + using __result = array...>, sizeof...(_Fs)>; + return __result{_VSTD::forward<_Fs>(__fs)...}; + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_dispatch(index_sequence<_Is...>) { + struct __dispatcher { + static constexpr decltype(auto) __dispatch(_Fp __f, _Vs... __vs) { + return __invoke_constexpr( + static_cast<_Fp>(__f), + __access::__base::__get_alt<_Is>(static_cast<_Vs>(__vs))...); + } + }; + return _VSTD::addressof(__dispatcher::__dispatch); + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fdiagonal_impl() { + return __make_dispatch<_Fp, _Vs...>( + index_sequence<(__identity<_Vs>{}, _Ip)...>{}); + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fdiagonal_impl(index_sequence<_Is...>) { + return __base::__make_farray(__make_fdiagonal_impl<_Is, _Fp, _Vs...>()...); + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fdiagonal() { + constexpr size_t _Np = decay_t<_Vp>::__size(); + static_assert(__all<(_Np == decay_t<_Vs>::__size())...>::value); + return __make_fdiagonal_impl<_Fp, _Vp, _Vs...>(make_index_sequence<_Np>{}); + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fmatrix_impl(index_sequence<_Is...> __is) { + return __make_dispatch<_Fp, _Vs...>(__is); + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fmatrix_impl(index_sequence<_Is...>, + index_sequence<_Js...>, + _Ls... __ls) { + return __base::__make_farray(__make_fmatrix_impl<_Fp, _Vs...>( + index_sequence<_Is..., _Js>{}, __ls...)...); + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_fmatrix() { + return __make_fmatrix_impl<_Fp, _Vs...>( + index_sequence<>{}, make_index_sequence::__size()>{}...); + } +}; + +struct __variant { + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) + __visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) { + return __base::__visit_alt_at(__index, + _VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs).__impl...); + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor, + _Vs&&... __vs) { + return __base::__visit_alt(_VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs).__impl...); + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) + __visit_value_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) { + return __visit_alt_at( + __index, + __make_value_visitor(_VSTD::forward<_Visitor>(__visitor)), + _VSTD::forward<_Vs>(__vs)...); + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr decltype(auto) __visit_value(_Visitor&& __visitor, + _Vs&&... __vs) { + return __visit_alt( + __make_value_visitor(_VSTD::forward<_Visitor>(__visitor)), + _VSTD::forward<_Vs>(__vs)...); + } + +private: + template + static constexpr void __std_visit_exhaustive_visitor_check() { + static_assert(is_callable_v<_Visitor(_Values...)>, + "`std::visit` requires the visitor to be exhaustive."); + } + + template + struct __value_visitor { + template + inline _LIBCPP_INLINE_VISIBILITY + constexpr decltype(auto) operator()(_Alts&&... __alts) const { + __std_visit_exhaustive_visitor_check< + _Visitor, + decltype(_VSTD::forward<_Alts>(__alts).__value)...>(); + return __invoke_constexpr(_VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Alts>(__alts).__value...); + } + _Visitor&& __visitor; + }; + + template + inline _LIBCPP_INLINE_VISIBILITY + static constexpr auto __make_value_visitor(_Visitor&& __visitor) { + return __value_visitor<_Visitor>{_VSTD::forward<_Visitor>(__visitor)}; + } +}; + +} // namespace __visitation + +template +struct _LIBCPP_TYPE_VIS_ONLY __alt { + using __value_type = _Tp; + + template + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr __alt(in_place_t, _Args&&... __args) + : __value(_VSTD::forward<_Args>(__args)...) {} + + __value_type __value; +}; + +template <_Trait _DestructibleTrait, size_t _Index, class... _Types> +union _LIBCPP_TYPE_VIS_ONLY __union; + +template <_Trait _DestructibleTrait, size_t _Index> +union _LIBCPP_TYPE_VIS_ONLY __union<_DestructibleTrait, _Index> {}; + +#define _LIBCPP_VARIANT_UNION(destructible_trait, destructor) \ + template \ + union _LIBCPP_TYPE_VIS_ONLY __union { \ + public: \ + inline _LIBCPP_INLINE_VISIBILITY \ + explicit constexpr __union(__valueless_t) noexcept : __dummy{} {} \ + \ + template \ + inline _LIBCPP_INLINE_VISIBILITY \ + explicit constexpr __union(in_place_index_t<0>, _Args&&... __args) \ + : __head(in_place, _VSTD::forward<_Args>(__args)...) {} \ + \ + template \ + inline _LIBCPP_INLINE_VISIBILITY \ + explicit constexpr __union(in_place_index_t<_Ip>, _Args&&... __args) \ + : __tail(in_place_index<_Ip - 1>, _VSTD::forward<_Args>(__args)...) {} \ + \ + __union(const __union&) = default; \ + __union(__union&&) = default; \ + \ + destructor \ + \ + __union& operator=(const __union&) = default; \ + __union& operator=(__union&&) = default; \ + \ + private: \ + char __dummy; \ + __alt<_Index, _Tp> __head; \ + __union __tail; \ + \ + friend struct __access::__union; \ + } + +_LIBCPP_VARIANT_UNION(_Trait::_TriviallyAvailable, ~__union() = default;); +_LIBCPP_VARIANT_UNION(_Trait::_Available, ~__union() {}); +_LIBCPP_VARIANT_UNION(_Trait::_Unavailable, ~__union() = delete;); + +#undef _LIBCPP_VARIANT_UNION + +template <_Trait _DestructibleTrait, class... _Types> +class _LIBCPP_TYPE_VIS_ONLY __base { +public: + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr __base(__valueless_t tag) noexcept + : __index(__variant_npos), __data(tag) {} + + template + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr __base(in_place_index_t<_Ip>, _Args&&... __args) + : __index(_Ip), + __data(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {} + + inline _LIBCPP_INLINE_VISIBILITY + constexpr bool valueless_by_exception() const noexcept { + return index() == variant_npos; + } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr size_t index() const noexcept { + return __index == __variant_npos ? variant_npos : __index; + } + +protected: + inline _LIBCPP_INLINE_VISIBILITY + constexpr auto&& __as_base() & { return *this; } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr auto&& __as_base() && { return _VSTD::move(*this); } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr auto&& __as_base() const & { return *this; } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr auto&& __as_base() const && { return _VSTD::move(*this); } + + inline _LIBCPP_INLINE_VISIBILITY + static constexpr size_t __size() { return sizeof...(_Types); } + + __union<_DestructibleTrait, 0, _Types...> __data; + unsigned int __index; + + friend struct __access::__base; + friend struct __visitation::__base; +}; + +template +class _LIBCPP_TYPE_VIS_ONLY __destructor; + +#define _LIBCPP_VARIANT_DESTRUCTOR(destructible_trait, destructor, destroy) \ + template \ + class _LIBCPP_TYPE_VIS_ONLY __destructor<__traits<_Types...>, \ + destructible_trait> \ + : public __base { \ + using __base_type = __base; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + __destructor(const __destructor&) = default; \ + __destructor(__destructor&&) = default; \ + destructor \ + __destructor& operator=(const __destructor&) = default; \ + __destructor& operator=(__destructor&&) = default; \ + \ + protected: \ + inline _LIBCPP_INLINE_VISIBILITY \ + destroy \ + } + +_LIBCPP_VARIANT_DESTRUCTOR( + _Trait::_TriviallyAvailable, + ~__destructor() = default;, + void __destroy() noexcept { this->__index = __variant_npos; }); + +_LIBCPP_VARIANT_DESTRUCTOR( + _Trait::_Available, + ~__destructor() { __destroy(); }, + void __destroy() noexcept { + if (!this->valueless_by_exception()) { + __visitation::__base::__visit_alt( + [](auto& __alt) noexcept { + using __alt_type = decay_t; + __alt.~__alt_type(); + }, + *this); + } + this->__index = __variant_npos; + }); + +_LIBCPP_VARIANT_DESTRUCTOR( + _Trait::_Unavailable, + ~__destructor() = delete;, + void __destroy() noexcept = delete;); + +#undef _LIBCPP_VARIANT_DESTRUCTOR + +template +class _LIBCPP_TYPE_VIS_ONLY __constructor : public __destructor<_Traits> { + using __base_type = __destructor<_Traits>; + +public: + using __base_type::__base_type; + using __base_type::operator=; + +protected: + template + inline _LIBCPP_INLINE_VISIBILITY + static void __construct_alt(__alt<_Ip, _Tp>& __a, _Args&&... __args) { + ::new (_VSTD::addressof(__a)) + __alt<_Ip, _Tp>(in_place, _VSTD::forward<_Args>(__args)...); + } + + template + inline _LIBCPP_INLINE_VISIBILITY + static void __generic_construct(__constructor& __lhs, _Rhs&& __rhs) { + __lhs.__destroy(); + if (!__rhs.valueless_by_exception()) { + __visitation::__base::__visit_alt_at( + __rhs.index(), + [](auto& __lhs_alt, auto&& __rhs_alt) { + __construct_alt( + __lhs_alt, + _VSTD::forward(__rhs_alt).__value); + }, + __lhs, _VSTD::forward<_Rhs>(__rhs)); + __lhs.__index = __rhs.index(); + } + } +}; + +template +class _LIBCPP_TYPE_VIS_ONLY __move_constructor; + +#define _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(move_constructible_trait, \ + move_constructor) \ + template \ + class _LIBCPP_TYPE_VIS_ONLY __move_constructor<__traits<_Types...>, \ + move_constructible_trait> \ + : public __constructor<__traits<_Types...>> { \ + using __base_type = __constructor<__traits<_Types...>>; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + __move_constructor(const __move_constructor&) = default; \ + move_constructor \ + ~__move_constructor() = default; \ + __move_constructor& operator=(const __move_constructor&) = default; \ + __move_constructor& operator=(__move_constructor&&) = default; \ + } + +_LIBCPP_VARIANT_MOVE_CONSTRUCTOR( + _Trait::_TriviallyAvailable, + __move_constructor(__move_constructor&& __that) = default;); + +_LIBCPP_VARIANT_MOVE_CONSTRUCTOR( + _Trait::_Available, + __move_constructor(__move_constructor&& __that) noexcept( + __all...>::value) + : __move_constructor(__valueless_t{}) { + this->__generic_construct(*this, _VSTD::move(__that)); + }); + +_LIBCPP_VARIANT_MOVE_CONSTRUCTOR( + _Trait::_Unavailable, + __move_constructor(__move_constructor&&) = delete;); + +#undef _LIBCPP_VARIANT_MOVE_CONSTRUCTOR + +template +class _LIBCPP_TYPE_VIS_ONLY __copy_constructor; + +#define _LIBCPP_VARIANT_COPY_CONSTRUCTOR(copy_constructible_trait, \ + copy_constructor) \ + template \ + class _LIBCPP_TYPE_VIS_ONLY __copy_constructor<__traits<_Types...>, \ + copy_constructible_trait> \ + : public __move_constructor<__traits<_Types...>> { \ + using __base_type = __move_constructor<__traits<_Types...>>; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + copy_constructor \ + __copy_constructor(__copy_constructor&&) = default; \ + ~__copy_constructor() = default; \ + __copy_constructor& operator=(const __copy_constructor&) = default; \ + __copy_constructor& operator=(__copy_constructor&&) = default; \ + } + +_LIBCPP_VARIANT_COPY_CONSTRUCTOR( + _Trait::_TriviallyAvailable, + __copy_constructor(const __copy_constructor& __that) = default;); + +_LIBCPP_VARIANT_COPY_CONSTRUCTOR( + _Trait::_Available, + __copy_constructor(const __copy_constructor& __that) + : __copy_constructor(__valueless_t{}) { + this->__generic_construct(*this, __that); + }); + +_LIBCPP_VARIANT_COPY_CONSTRUCTOR( + _Trait::_Unavailable, + __copy_constructor(const __copy_constructor&) = delete;); + +#undef _LIBCPP_VARIANT_COPY_CONSTRUCTOR + +template +class _LIBCPP_TYPE_VIS_ONLY __assignment : public __copy_constructor<_Traits> { + using __base_type = __copy_constructor<_Traits>; + +public: + using __base_type::__base_type; + using __base_type::operator=; + + template + inline _LIBCPP_INLINE_VISIBILITY + void __emplace(_Args&&... __args) { + this->__destroy(); + this->__construct_alt(__access::__base::__get_alt<_Ip>(*this), + _VSTD::forward<_Args>(__args)...); + this->__index = _Ip; + } + +protected: + template + inline _LIBCPP_INLINE_VISIBILITY + void __assign_alt(__alt<_Ip, _Tp>& __a, + _Arg&& __arg, + bool_constant<_CopyAssign> __tag) { + if (this->index() == _Ip) { + __a.__value = _VSTD::forward<_Arg>(__arg); + } else { + struct { + void operator()(true_type) const { + __this->__emplace<_Ip>(_Tp(_VSTD::forward<_Arg>(__arg))); + } + void operator()(false_type) const { + __this->__emplace<_Ip>(_VSTD::forward<_Arg>(__arg)); + } + __assignment* __this; + _Arg&& __arg; + } __impl{this, _VSTD::forward<_Arg>(__arg)}; + __impl(__tag); + } + } + + template + inline _LIBCPP_INLINE_VISIBILITY + void __generic_assign(_That&& __that) { + if (this->valueless_by_exception() && __that.valueless_by_exception()) { + // do nothing. + } else if (__that.valueless_by_exception()) { + this->__destroy(); + } else { + __visitation::__base::__visit_alt_at( + __that.index(), + [this](auto& __this_alt, auto&& __that_alt) { + this->__assign_alt( + __this_alt, + _VSTD::forward(__that_alt).__value, + is_lvalue_reference<_That>{}); + }, + *this, _VSTD::forward<_That>(__that)); + } + } +}; + +template +class _LIBCPP_TYPE_VIS_ONLY __move_assignment; + +#define _LIBCPP_VARIANT_MOVE_ASSIGNMENT(move_assignable_trait, \ + move_assignment) \ + template \ + class _LIBCPP_TYPE_VIS_ONLY __move_assignment<__traits<_Types...>, \ + move_assignable_trait> \ + : public __assignment<__traits<_Types...>> { \ + using __base_type = __assignment<__traits<_Types...>>; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + __move_assignment(const __move_assignment&) = default; \ + __move_assignment(__move_assignment&&) = default; \ + ~__move_assignment() = default; \ + __move_assignment& operator=(const __move_assignment&) = default; \ + move_assignment \ + } + +_LIBCPP_VARIANT_MOVE_ASSIGNMENT( + _Trait::_TriviallyAvailable, + __move_assignment& operator=(__move_assignment&& __that) = default;); + +_LIBCPP_VARIANT_MOVE_ASSIGNMENT( + _Trait::_Available, + __move_assignment& operator=(__move_assignment&& __that) noexcept( + __all<(is_nothrow_move_constructible_v<_Types> && + is_nothrow_move_assignable_v<_Types>)...>::value) { + this->__generic_assign(_VSTD::move(__that)); + return *this; + }); + +_LIBCPP_VARIANT_MOVE_ASSIGNMENT( + _Trait::_Unavailable, + __move_assignment& operator=(__move_assignment&&) = delete;); + +#undef _LIBCPP_VARIANT_MOVE_ASSIGNMENT + +template +class _LIBCPP_TYPE_VIS_ONLY __copy_assignment; + +#define _LIBCPP_VARIANT_COPY_ASSIGNMENT(copy_assignable_trait, \ + copy_assignment) \ + template \ + class _LIBCPP_TYPE_VIS_ONLY __copy_assignment<__traits<_Types...>, \ + copy_assignable_trait> \ + : public __move_assignment<__traits<_Types...>> { \ + using __base_type = __move_assignment<__traits<_Types...>>; \ + \ + public: \ + using __base_type::__base_type; \ + using __base_type::operator=; \ + \ + __copy_assignment(const __copy_assignment&) = default; \ + __copy_assignment(__copy_assignment&&) = default; \ + ~__copy_assignment() = default; \ + copy_assignment \ + __copy_assignment& operator=(__copy_assignment&&) = default; \ + } + +_LIBCPP_VARIANT_COPY_ASSIGNMENT( + _Trait::_TriviallyAvailable, + __copy_assignment& operator=(const __copy_assignment& __that) = default;); + +_LIBCPP_VARIANT_COPY_ASSIGNMENT( + _Trait::_Available, + __copy_assignment& operator=(const __copy_assignment& __that) { + this->__generic_assign(__that); + return *this; + }); + +_LIBCPP_VARIANT_COPY_ASSIGNMENT( + _Trait::_Unavailable, + __copy_assignment& operator=(const __copy_assignment&) = delete;); + +#undef _LIBCPP_VARIANT_COPY_ASSIGNMENT + +template +class _LIBCPP_TYPE_VIS_ONLY __impl + : public __copy_assignment<__traits<_Types...>> { + using __base_type = __copy_assignment<__traits<_Types...>>; + +public: + using __base_type::__base_type; + using __base_type::operator=; + + template + inline _LIBCPP_INLINE_VISIBILITY + void __assign(_Arg&& __arg) { + this->__assign_alt(__access::__base::__get_alt<_Ip>(*this), + _VSTD::forward<_Arg>(__arg), + false_type{}); + } + + inline _LIBCPP_INLINE_VISIBILITY + void __swap(__impl& __that) { + if (this->valueless_by_exception() && __that.valueless_by_exception()) { + // do nothing. + } else if (this->index() == __that.index()) { + __visitation::__base::__visit_alt_at( + this->index(), + [](auto& __this_alt, auto& __that_alt) { + using _VSTD::swap; + swap(__this_alt.__value, __that_alt.__value); + }, + *this, + __that); + } else { + __impl* __lhs = this; + __impl* __rhs = _VSTD::addressof(__that); + if (__lhs->__move_nothrow() && !__rhs->__move_nothrow()) { + _VSTD::swap(__lhs, __rhs); + } + __impl __tmp(_VSTD::move(*__rhs)); +#ifndef _LIBCPP_NO_EXCEPTIONS + // EXTENSION: When the move construction of `__lhs` into `__rhs` throws + // and `__tmp` is nothrow move constructible then we move `__tmp` back + // into `__rhs` and provide the strong exception safety guarentee. + try { + this->__generic_construct(*__rhs, _VSTD::move(*__lhs)); + } catch (...) { + if (__tmp.__move_nothrow()) { + this->__generic_construct(*__rhs, _VSTD::move(__tmp)); + } + throw; + } +#else + this->__generic_construct(*__rhs, _VSTD::move(*__lhs)); +#endif + this->__generic_construct(*__lhs, _VSTD::move(__tmp)); + } + } + +private: + inline _LIBCPP_INLINE_VISIBILITY + bool __move_nothrow() const { + constexpr bool __results[] = {is_nothrow_move_constructible_v<_Types>...}; + return this->valueless_by_exception() || __results[this->index()]; + } +}; + +template +struct __overload; + +template <> +struct __overload<> { void operator()() const; }; + +template +struct __overload<_Tp, _Types...> : __overload<_Types...> { + using __overload<_Types...>::operator(); + __identity<_Tp> operator()(_Tp) const; +}; + +template +using __best_match_t = typename result_of_t<__overload<_Types...>(_Tp&&)>::type; + +} // __variant_detail + +template +class _LIBCPP_TYPE_VIS_ONLY variant + : private __sfinae_ctor_base< + __all...>::value, + __all...>::value>, + private __sfinae_assign_base< + __all<(is_copy_constructible_v<_Types> && + is_move_constructible_v<_Types> && + is_copy_assignable_v<_Types>)...>::value, + __all<(is_move_constructible_v<_Types> && + is_move_assignable_v<_Types>)...>::value> { + static_assert(0 < sizeof...(_Types), + "variant must consist of at least one alternative."); + + static_assert(__all...>::value, + "variant can not have an array type as an alternative."); + + static_assert(__all...>::value, + "variant can not have a reference type as an alternative."); + + static_assert(__all...>::value, + "variant can not have a void type as an alternative."); + + using __first_type = variant_alternative_t<0, variant>; + +public: + template , + _Dummy>::value, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + constexpr variant() noexcept(is_nothrow_default_constructible_v<__first_type>) + : __impl(in_place_index<0>) {} + + variant(const variant&) = default; + variant(variant&&) = default; + + template < + class _Arg, + enable_if_t, variant>, int> = 0, + class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + constexpr variant(_Arg&& __arg) noexcept( + is_nothrow_constructible_v<_Tp, _Arg>) + : __impl(in_place_index<_Ip>, _VSTD::forward<_Arg>(__arg)) {} + + template = 0, + class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, + enable_if_t, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr variant( + in_place_index_t<_Ip>, + _Args&&... __args) noexcept(is_nothrow_constructible_v<_Tp, _Args...>) + : __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {} + + template < + size_t _Ip, + class _Up, + class... _Args, + enable_if_t<(_Ip < sizeof...(_Types)), int> = 0, + class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, + enable_if_t&, _Args...>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr variant( + in_place_index_t<_Ip>, + initializer_list<_Up> __il, + _Args&&... __args) noexcept( + is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>) + : __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {} + + template < + class _Tp, + class... _Args, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr variant(in_place_type_t<_Tp>, _Args&&... __args) noexcept( + is_nothrow_constructible_v<_Tp, _Args...>) + : __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {} + + template < + class _Tp, + class _Up, + class... _Args, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t&, _Args...>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + explicit constexpr variant( + in_place_type_t<_Tp>, + initializer_list<_Up> __il, + _Args&&... __args) noexcept( + is_nothrow_constructible_v<_Tp, initializer_list< _Up>&, _Args...>) + : __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {} + + ~variant() = default; + + variant& operator=(const variant&) = default; + variant& operator=(variant&&) = default; + + template < + class _Arg, + enable_if_t, variant>, int> = 0, + class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t && is_constructible_v<_Tp, _Arg>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + variant& operator=(_Arg&& __arg) noexcept( + is_nothrow_assignable_v<_Tp&, _Arg> && + is_nothrow_constructible_v<_Tp, _Arg>) { + __impl.template __assign<_Ip>(_VSTD::forward<_Arg>(__arg)); + return *this; + } + + template < + size_t _Ip, + class... _Args, + enable_if_t<(_Ip < sizeof...(_Types)), int> = 0, + class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, + enable_if_t, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + void emplace(_Args&&... __args) { + __impl.template __emplace<_Ip>(_VSTD::forward<_Args>(__args)...); + } + + template < + size_t _Ip, + class _Up, + class... _Args, + enable_if_t<(_Ip < sizeof...(_Types)), int> = 0, + class _Tp = variant_alternative_t<_Ip, variant<_Types...>>, + enable_if_t&, _Args...>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + void emplace(initializer_list<_Up> __il, _Args&&... __args) { + __impl.template __emplace<_Ip>(__il, _VSTD::forward<_Args>(__args)...); + } + + template < + class _Tp, + class... _Args, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t, int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + void emplace(_Args&&... __args) { + __impl.template __emplace<_Ip>(_VSTD::forward<_Args>(__args)...); + } + + template < + class _Tp, + class _Up, + class... _Args, + size_t _Ip = + __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value, + enable_if_t&, _Args...>, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + void emplace(initializer_list<_Up> __il, _Args&&... __args) { + __impl.template __emplace<_Ip>(__il, _VSTD::forward<_Args>(__args)...); + } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr bool valueless_by_exception() const noexcept { + return __impl.valueless_by_exception(); + } + + inline _LIBCPP_INLINE_VISIBILITY + constexpr size_t index() const noexcept { return __impl.index(); } + + template < + bool _Dummy = true, + enable_if_t< + __all<( + __dependent_type, _Dummy>::value && + __dependent_type, _Dummy>::value)...>::value, + int> = 0> + inline _LIBCPP_INLINE_VISIBILITY + void swap(variant& __that) noexcept( + __all<(is_nothrow_move_constructible_v<_Types> && + is_nothrow_swappable_v<_Types>)...>::value) { + __impl.__swap(__that.__impl); + } + +private: + __variant_detail::__impl<_Types...> __impl; + + friend struct __variant_detail::__access::__variant; + friend struct __variant_detail::__visitation::__variant; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool __holds_alternative(const variant<_Types...>& __v) noexcept { + return __v.index() == _Ip; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept { + return __holds_alternative<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +static constexpr auto&& __generic_get(_Vp&& __v) { + using __variant_detail::__access::__variant; + if (!__holds_alternative<_Ip>(__v)) { + throw bad_variant_access{}; + } + return __variant::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v)).__value; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr variant_alternative_t<_Ip, variant<_Types...>>& get( + variant<_Types...>& __v) { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v>>); + return __generic_get<_Ip>(__v); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr variant_alternative_t<_Ip, variant<_Types...>>&& get( + variant<_Types...>&& __v) { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v>>); + return __generic_get<_Ip>(_VSTD::move(__v)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr const variant_alternative_t<_Ip, variant<_Types...>>& get( + const variant<_Types...>& __v) { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v>>); + return __generic_get<_Ip>(__v); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr const variant_alternative_t<_Ip, variant<_Types...>>&& get( + const variant<_Types...>&& __v) { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v>>); + return __generic_get<_Ip>(_VSTD::move(__v)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp& get(variant<_Types...>& __v) { + static_assert(!is_void_v<_Tp>); + return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp&& get(variant<_Types...>&& __v) { + static_assert(!is_void_v<_Tp>); + return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>( + _VSTD::move(__v)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr const _Tp& get(const variant<_Types...>& __v) { + static_assert(!is_void_v<_Tp>); + return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr const _Tp&& get(const variant<_Types...>&& __v) { + static_assert(!is_void_v<_Tp>); + return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>( + _VSTD::move(__v)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr auto* __generic_get_if(_Vp* __v) noexcept { + using __variant_detail::__access::__variant; + return __v && __holds_alternative<_Ip>(*__v) + ? _VSTD::addressof(__variant::__get_alt<_Ip>(*__v).__value) + : nullptr; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr add_pointer_t>> +get_if(variant<_Types...>* __v) noexcept { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v>>); + return __generic_get_if<_Ip>(__v); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr add_pointer_t>> +get_if(const variant<_Types...>* __v) noexcept { + static_assert(_Ip < sizeof...(_Types)); + static_assert(!is_void_v>>); + return __generic_get_if<_Ip>(__v); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr add_pointer_t<_Tp> +get_if(variant<_Types...>* __v) noexcept { + static_assert(!is_void_v<_Tp>); + return _VSTD::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr add_pointer_t +get_if(const variant<_Types...>* __v) noexcept { + static_assert(!is_void_v<_Tp>); + return _VSTD::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__lhs.index() != __rhs.index()) return false; + if (__lhs.valueless_by_exception()) return true; + return __variant::__visit_value_at(__lhs.index(), equal_to<>{}, __lhs, __rhs); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__lhs.index() != __rhs.index()) return true; + if (__lhs.valueless_by_exception()) return false; + return __variant::__visit_value_at( + __lhs.index(), not_equal_to<>{}, __lhs, __rhs); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator<(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__rhs.valueless_by_exception()) return false; + if (__lhs.valueless_by_exception()) return true; + if (__lhs.index() < __rhs.index()) return true; + if (__lhs.index() > __rhs.index()) return false; + return __variant::__visit_value_at(__lhs.index(), less<>{}, __lhs, __rhs); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator>(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__lhs.valueless_by_exception()) return false; + if (__rhs.valueless_by_exception()) return true; + if (__lhs.index() > __rhs.index()) return true; + if (__lhs.index() < __rhs.index()) return false; + return __variant::__visit_value_at(__lhs.index(), greater<>{}, __lhs, __rhs); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator<=(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__lhs.valueless_by_exception()) return true; + if (__rhs.valueless_by_exception()) return false; + if (__lhs.index() < __rhs.index()) return true; + if (__lhs.index() > __rhs.index()) return false; + return __variant::__visit_value_at( + __lhs.index(), less_equal<>{}, __lhs, __rhs); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator>=(const variant<_Types...>& __lhs, + const variant<_Types...>& __rhs) { + using __variant_detail::__visitation::__variant; + if (__rhs.valueless_by_exception()) return true; + if (__lhs.valueless_by_exception()) return false; + if (__lhs.index() > __rhs.index()) return true; + if (__lhs.index() < __rhs.index()) return false; + return __variant::__visit_value_at( + __lhs.index(), greater_equal<>{}, __lhs, __rhs); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs) { + using __variant_detail::__visitation::__variant; + bool __results[] = {__vs.valueless_by_exception()...}; + for (bool __result : __results) { + if (__result) { + throw bad_variant_access{}; + } + } + return __variant::__visit_value(_VSTD::forward<_Visitor>(__visitor), + _VSTD::forward<_Vs>(__vs)...); +} + +struct _LIBCPP_TYPE_VIS_ONLY monostate {}; + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator<(monostate, monostate) noexcept { return false; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator>(monostate, monostate) noexcept { return false; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator<=(monostate, monostate) noexcept { return true; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator>=(monostate, monostate) noexcept { return true; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator==(monostate, monostate) noexcept { return true; } + +inline _LIBCPP_INLINE_VISIBILITY +constexpr bool operator!=(monostate, monostate) noexcept { return false; } + +template +inline _LIBCPP_INLINE_VISIBILITY +auto swap(variant<_Types...>& __lhs, + variant<_Types...>& __rhs) noexcept(noexcept(__lhs.swap(__rhs))) + -> decltype(__lhs.swap(__rhs)) { + __lhs.swap(__rhs); +} + +template +struct _LIBCPP_TYPE_VIS_ONLY hash> { + using argument_type = variant<_Types...>; + using result_type = size_t; + + inline _LIBCPP_INLINE_VISIBILITY + result_type operator()(const argument_type& __v) const { + using __variant_detail::__visitation::__variant; + return __v.valueless_by_exception() + ? __v.index() + : __variant::__visit_alt( + [](const auto& __alt) { + using __alt_type = decay_t; + using __value_type = typename __alt_type::__value_type; + return hash<__value_type>{}(__alt.__value); + }, + __v); + } +}; + +template <> +struct _LIBCPP_TYPE_VIS_ONLY hash { + using argument_type = monostate; + using result_type = size_t; + + inline _LIBCPP_INLINE_VISIBILITY + result_type operator()(const argument_type&) const { return 0; } +}; + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_VARIANT diff --git a/libcxx/src/variant.cpp b/libcxx/src/variant.cpp new file mode 100644 index 0000000..5bb508c --- /dev/null +++ b/libcxx/src/variant.cpp @@ -0,0 +1,18 @@ +//===------------------------ variant.cpp ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "variant" + +namespace std { + +const char* bad_variant_access::what() const noexcept { + return "bad_variant_access"; +} + +} // namespace std diff --git a/libcxx/test/libcxx/utilities/variant/variant.variant/variant.assign/copy.pass.cpp b/libcxx/test/libcxx/utilities/variant/variant.variant/variant.assign/copy.pass.cpp new file mode 100644 index 0000000..c0084e0b --- /dev/null +++ b/libcxx/test/libcxx/utilities/variant/variant.variant/variant.assign/copy.pass.cpp @@ -0,0 +1,181 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// template class variant; + +// variant& operator=(variant const&); + +#include +#include + +#include "test_macros.h" + +struct NTCopyAssign { + constexpr NTCopyAssign(int v) : value(v) {} + NTCopyAssign(const NTCopyAssign &) = default; + NTCopyAssign(NTCopyAssign &&) = default; + NTCopyAssign &operator=(const NTCopyAssign &that) { + value = that.value; + return *this; + }; + NTCopyAssign &operator=(NTCopyAssign &&) = delete; + int value; +}; + +static_assert(!std::is_trivially_copy_assignable::value, ""); +static_assert(std::is_copy_assignable::value, ""); + +struct TCopyAssign { + constexpr TCopyAssign(int v) : value(v) {} + TCopyAssign(const TCopyAssign &) = default; + TCopyAssign(TCopyAssign &&) = default; + TCopyAssign &operator=(const TCopyAssign &) = default; + TCopyAssign &operator=(TCopyAssign &&) = delete; + int value; +}; + +static_assert(std::is_trivially_copy_assignable::value, ""); + +struct TCopyAssignNTMoveAssign { + constexpr TCopyAssignNTMoveAssign(int v) : value(v) {} + TCopyAssignNTMoveAssign(const TCopyAssignNTMoveAssign &) = default; + TCopyAssignNTMoveAssign(TCopyAssignNTMoveAssign &&) = default; + TCopyAssignNTMoveAssign &operator=(const TCopyAssignNTMoveAssign &) = default; + TCopyAssignNTMoveAssign &operator=(TCopyAssignNTMoveAssign &&that) { + value = that.value; + that.value = -1; + return *this; + } + int value; +}; + +static_assert(std::is_trivially_copy_assignable_v); + +void test_copy_assignment_sfinae() { + { + using V = std::variant; + static_assert(std::is_trivially_copy_assignable::value, ""); + } + { + using V = std::variant; + static_assert(!std::is_trivially_copy_assignable::value, ""); + static_assert(std::is_copy_assignable::value, ""); + } + { + using V = std::variant; + static_assert(std::is_trivially_copy_assignable::value, ""); + } + { + using V = std::variant; + static_assert(std::is_trivially_copy_assignable::value, ""); + } +} + +template struct Result { size_t index; T value; }; + +void test_copy_assignment_same_index() { + { + struct { + constexpr Result operator()() const { + using V = std::variant; + V v(43); + V v2(42); + v = v2; + return {v.index(), std::get<0>(v)}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 0); + static_assert(result.value == 42); + } + { + struct { + constexpr Result operator()() const { + using V = std::variant; + V v(43l); + V v2(42l); + v = v2; + return {v.index(), std::get<1>(v)}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 1); + static_assert(result.value == 42l); + } + { + struct { + constexpr Result operator()() const { + using V = std::variant; + V v(std::in_place_type, 43); + V v2(std::in_place_type, 42); + v = v2; + return {v.index(), std::get<1>(v).value}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 1); + static_assert(result.value == 42); + } + { + struct { + constexpr Result operator()() const { + using V = std::variant; + V v(std::in_place_type, 43); + V v2(std::in_place_type, 42); + v = v2; + return {v.index(), std::get<1>(v).value}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 1); + static_assert(result.value == 42); + } +} + +void test_copy_assignment_different_index() { + { + struct { + constexpr Result operator()() const { + using V = std::variant; + V v(43); + V v2(42l); + v = v2; + return {v.index(), std::get<1>(v)}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 1); + static_assert(result.value == 42l); + } + { + struct { + constexpr Result operator()() const { + using V = std::variant; + V v(std::in_place_type, 43); + V v2(std::in_place_type, 42); + v = v2; + return {v.index(), std::get<1>(v).value}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 1); + static_assert(result.value == 42); + } +} + +int main() { + test_copy_assignment_same_index(); + test_copy_assignment_different_index(); + test_copy_assignment_sfinae(); +} diff --git a/libcxx/test/libcxx/utilities/variant/variant.variant/variant.assign/move.pass.cpp b/libcxx/test/libcxx/utilities/variant/variant.variant/variant.assign/move.pass.cpp new file mode 100644 index 0000000..3c8436d --- /dev/null +++ b/libcxx/test/libcxx/utilities/variant/variant.variant/variant.assign/move.pass.cpp @@ -0,0 +1,167 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// template class variant; + +// variant& operator=(variant&&) noexcept(see below); + +#include +#include + +#include "test_macros.h" + +struct NTMoveAssign { + constexpr NTMoveAssign(int v) : value(v) {} + NTMoveAssign(const NTMoveAssign &) = default; + NTMoveAssign(NTMoveAssign &&) = default; + NTMoveAssign &operator=(const NTMoveAssign &that) = default; + NTMoveAssign &operator=(NTMoveAssign &&that) { + value = that.value; + that.value = -1; + return *this; + }; + int value; +}; + +static_assert(!std::is_trivially_move_assignable::value, ""); +static_assert(std::is_move_assignable::value, ""); + +struct TMoveAssign { + constexpr TMoveAssign(int v) : value(v) {} + TMoveAssign(const TMoveAssign &) = delete; + TMoveAssign(TMoveAssign &&) = default; + TMoveAssign &operator=(const TMoveAssign &) = delete; + TMoveAssign &operator=(TMoveAssign &&) = default; + int value; +}; + +static_assert(std::is_trivially_move_assignable::value, ""); + +struct TMoveAssignNTCopyAssign { + constexpr TMoveAssignNTCopyAssign(int v) : value(v) {} + TMoveAssignNTCopyAssign(const TMoveAssignNTCopyAssign &) = default; + TMoveAssignNTCopyAssign(TMoveAssignNTCopyAssign &&) = default; + TMoveAssignNTCopyAssign &operator=(const TMoveAssignNTCopyAssign &that) { + value = that.value; + return *this; + } + TMoveAssignNTCopyAssign &operator=(TMoveAssignNTCopyAssign &&) = default; + int value; +}; + +static_assert(std::is_trivially_move_assignable_v); + +void test_move_assignment_sfinae() { + { + using V = std::variant; + static_assert(std::is_trivially_move_assignable::value, ""); + } + { + using V = std::variant; + static_assert(!std::is_trivially_move_assignable::value, ""); + static_assert(std::is_move_assignable::value, ""); + } + { + using V = std::variant; + static_assert(std::is_trivially_move_assignable::value, ""); + } + { + using V = std::variant; + static_assert(std::is_trivially_move_assignable::value, ""); + } +} + +template struct Result { size_t index; T value; }; + +void test_move_assignment_same_index() { + { + struct { + constexpr Result operator()() const { + using V = std::variant; + V v(43); + V v2(42); + v = std::move(v2); + return {v.index(), std::get<0>(v)}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 0); + static_assert(result.value == 42); + } + { + struct { + constexpr Result operator()() const { + using V = std::variant; + V v(43l); + V v2(42l); + v = std::move(v2); + return {v.index(), std::get<1>(v)}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 1); + static_assert(result.value == 42l); + } + { + struct { + constexpr Result operator()() const { + using V = std::variant; + V v(std::in_place_type, 43); + V v2(std::in_place_type, 42); + v = std::move(v2); + return {v.index(), std::get<1>(v).value}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 1); + static_assert(result.value == 42); + } +} + +void test_move_assignment_different_index() { + { + struct { + constexpr Result operator()() const { + using V = std::variant; + V v(43); + V v2(42l); + v = std::move(v2); + return {v.index(), std::get<1>(v)}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 1); + static_assert(result.value == 42l); + } + { + struct { + constexpr Result operator()() const { + using V = std::variant; + V v(std::in_place_type, 43); + V v2(std::in_place_type, 42); + v = std::move(v2); + return {v.index(), std::get<1>(v).value}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 1); + static_assert(result.value == 42); + } +} + +int main() { + test_move_assignment_same_index(); + test_move_assignment_different_index(); + test_move_assignment_sfinae(); +} diff --git a/libcxx/test/libcxx/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp b/libcxx/test/libcxx/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp new file mode 100644 index 0000000..59c4330 --- /dev/null +++ b/libcxx/test/libcxx/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp @@ -0,0 +1,120 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// template class variant; + +// variant(variant const&); + +#include +#include + +#include "test_macros.h" + +struct NTCopy { + constexpr NTCopy(int v) : value(v) {} + NTCopy(const NTCopy &that) : value(that.value) {} + NTCopy(NTCopy &&) = delete; + int value; +}; + +static_assert(!std::is_trivially_copy_constructible::value, ""); +static_assert(std::is_copy_constructible::value, ""); + +struct TCopy { + constexpr TCopy(int v) : value(v) {} + TCopy(TCopy const &) = default; + TCopy(TCopy &&) = delete; + int value; +}; + +static_assert(std::is_trivially_copy_constructible::value, ""); + +struct TCopyNTMove { + constexpr TCopyNTMove(int v) : value(v) {} + TCopyNTMove(const TCopyNTMove&) = default; + TCopyNTMove(TCopyNTMove&& that) : value(that.value) { that.value = -1; } + int value; +}; + +static_assert(std::is_trivially_copy_constructible::value, ""); + +void test_copy_ctor_sfinae() { + { + using V = std::variant; + static_assert(std::is_trivially_copy_constructible::value, ""); + } + { + using V = std::variant; + static_assert(!std::is_trivially_copy_constructible::value, ""); + static_assert(std::is_copy_constructible::value, ""); + } + { + using V = std::variant; + static_assert(std::is_trivially_copy_constructible::value, ""); + } + { + using V = std::variant; + static_assert(std::is_trivially_copy_constructible::value, ""); + } +} + +void test_copy_ctor_basic() { + { + constexpr std::variant v(std::in_place_index<0>, 42); + static_assert(v.index() == 0); + constexpr std::variant v2 = v; + static_assert(v2.index() == 0); + static_assert(std::get<0>(v2) == 42); + } + { + constexpr std::variant v(std::in_place_index<1>, 42); + static_assert(v.index() == 1); + constexpr std::variant v2 = v; + static_assert(v2.index() == 1); + static_assert(std::get<1>(v2) == 42); + } + { + constexpr std::variant v(std::in_place_index<0>, 42); + static_assert(v.index() == 0); + constexpr std::variant v2(v); + static_assert(v2.index() == 0); + static_assert(std::get<0>(v2).value == 42); + } + { + constexpr std::variant v(std::in_place_index<1>, 42); + static_assert(v.index() == 1); + constexpr std::variant v2(v); + static_assert(v2.index() == 1); + static_assert(std::get<1>(v2).value == 42); + } + { + constexpr std::variant v(std::in_place_index<0>, 42); + static_assert(v.index() == 0); + constexpr std::variant v2(v); + static_assert(v2.index() == 0); + static_assert(std::get<0>(v2).value == 42); + } + { + constexpr std::variant v(std::in_place_index<1>, 42); + static_assert(v.index() == 1); + constexpr std::variant v2(v); + static_assert(v2.index() == 1); + static_assert(std::get<1>(v2).value == 42); + } +} + +int main() { + test_copy_ctor_basic(); + test_copy_ctor_sfinae(); +} diff --git a/libcxx/test/libcxx/utilities/variant/variant.variant/variant.ctor/move.pass.cpp b/libcxx/test/libcxx/utilities/variant/variant.variant/variant.ctor/move.pass.cpp new file mode 100644 index 0000000..e67a495 --- /dev/null +++ b/libcxx/test/libcxx/utilities/variant/variant.variant/variant.ctor/move.pass.cpp @@ -0,0 +1,153 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// template class variant; + +// variant(variant&&) noexcept(see below); + +#include +#include + +#include "test_macros.h" + +struct NTMove { + constexpr NTMove(int v) : value(v) {} + NTMove(const NTMove &) = delete; + NTMove(NTMove &&that) : value(that.value) { that.value = -1; } + int value; +}; + +static_assert(!std::is_trivially_move_constructible::value, ""); +static_assert(std::is_move_constructible::value, ""); + +struct TMove { + constexpr TMove(int v) : value(v) {} + TMove(const TMove &) = delete; + TMove(TMove &&) = default; + int value; +}; + +static_assert(std::is_trivially_move_constructible::value, ""); + +struct TMoveNTCopy { + constexpr TMoveNTCopy(int v) : value(v) {} + TMoveNTCopy(const TMoveNTCopy& that) : value(that.value) {} + TMoveNTCopy(TMoveNTCopy&&) = default; + int value; +}; + +static_assert(std::is_trivially_move_constructible::value, ""); + +void test_move_ctor_sfinae() { + { + using V = std::variant; + static_assert(std::is_trivially_move_constructible::value, ""); + } + { + using V = std::variant; + static_assert(!std::is_trivially_move_constructible::value, ""); + static_assert(std::is_move_constructible::value, ""); + } + { + using V = std::variant; + static_assert(std::is_trivially_move_constructible::value, ""); + } + { + using V = std::variant; + static_assert(std::is_trivially_move_constructible::value, ""); + } +} + +template +struct Result { size_t index; T value; }; + +void test_move_ctor_basic() { + { + struct { + constexpr Result operator()() const { + std::variant v(std::in_place_index<0>, 42); + std::variant v2 = std::move(v); + return {v2.index(), std::get<0>(std::move(v2))}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 0); + static_assert(result.value == 42); + } + { + struct { + constexpr Result operator()() const { + std::variant v(std::in_place_index<1>, 42); + std::variant v2 = std::move(v); + return {v2.index(), std::get<1>(std::move(v2))}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 1); + static_assert(result.value == 42); + } + { + struct { + constexpr Result operator()() const { + std::variant v(std::in_place_index<0>, 42); + std::variant v2(std::move(v)); + return {v2.index(), std::get<0>(std::move(v2))}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 0); + static_assert(result.value.value == 42); + } + { + struct { + constexpr Result operator()() const { + std::variant v(std::in_place_index<1>, 42); + std::variant v2(std::move(v)); + return {v2.index(), std::get<1>(std::move(v2))}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 1); + static_assert(result.value.value == 42); + } + { + struct { + constexpr Result operator()() const { + std::variant v(std::in_place_index<0>, 42); + std::variant v2(std::move(v)); + return {v2.index(), std::get<0>(std::move(v2))}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 0); + static_assert(result.value.value == 42); + } + { + struct { + constexpr Result operator()() const { + std::variant v(std::in_place_index<1>, 42); + std::variant v2(std::move(v)); + return {v2.index(), std::get<1>(std::move(v2))}; + } + } test; + constexpr auto result = test(); + static_assert(result.index == 1); + static_assert(result.value.value == 42); + } +} + +int main() { + test_move_ctor_basic(); + test_move_ctor_sfinae(); +} diff --git a/libcxx/test/libcxx/utilities/variant/version.pass.cpp b/libcxx/test/libcxx/utilities/variant/version.pass.cpp new file mode 100644 index 0000000..1db93e0 --- /dev/null +++ b/libcxx/test/libcxx/utilities/variant/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/utilities/variant/lit.local.cfg b/libcxx/test/std/utilities/variant/lit.local.cfg deleted file mode 100644 index 43671e2..0000000 --- a/libcxx/test/std/utilities/variant/lit.local.cfg +++ /dev/null @@ -1,5 +0,0 @@ - -# FIXME: Libc++ does not yet implement variant but other STLs benefit from -# having our tests in-tree. This must be removed when is added. -if 'libc++' in config.available_features: - config.unsupported = True diff --git a/libcxx/test/std/utilities/variant/variant.get/get_if_index.pass.cpp b/libcxx/test/std/utilities/variant/variant.get/get_if_index.pass.cpp index 2ea88e3..94cc080 100644 --- a/libcxx/test/std/utilities/variant/variant.get/get_if_index.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.get/get_if_index.pass.cpp @@ -32,17 +32,17 @@ void test_const_get_if() { static_assert(std::get_if<0>(v) == nullptr, ""); } { - using V = std::variant; + using V = std::variant; constexpr V v(42); ASSERT_NOEXCEPT(std::get_if<0>(&v)); - ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), int const *); + ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), const int *); static_assert(*std::get_if<0>(&v) == 42, ""); static_assert(std::get_if<1>(&v) == nullptr, ""); } { - using V = std::variant; + using V = std::variant; constexpr V v(42l); - ASSERT_SAME_TYPE(decltype(std::get_if<1>(&v)), long const *); + ASSERT_SAME_TYPE(decltype(std::get_if<1>(&v)), const long *); static_assert(*std::get_if<1>(&v) == 42, ""); static_assert(std::get_if<0>(&v) == nullptr, ""); } @@ -87,9 +87,9 @@ void test_get_if() { assert(std::get_if<1>(&v) == nullptr); } { - using V = std::variant; + using V = std::variant; V v(42l); - ASSERT_SAME_TYPE(decltype(std::get_if<1>(&v)), long *); + ASSERT_SAME_TYPE(decltype(std::get_if<1>(&v)), const long *); assert(*std::get_if<1>(&v) == 42); assert(std::get_if<0>(&v) == nullptr); } diff --git a/libcxx/test/std/utilities/variant/variant.get/get_if_type.pass.cpp b/libcxx/test/std/utilities/variant/variant.get/get_if_type.pass.cpp index 59ddef3..a8cc664 100644 --- a/libcxx/test/std/utilities/variant/variant.get/get_if_type.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.get/get_if_type.pass.cpp @@ -30,18 +30,18 @@ void test_const_get_if() { static_assert(std::get_if(v) == nullptr, ""); } { - using V = std::variant; + using V = std::variant; constexpr V v(42); ASSERT_NOEXCEPT(std::get_if(&v)); - ASSERT_SAME_TYPE(decltype(std::get_if(&v)), int const *); + ASSERT_SAME_TYPE(decltype(std::get_if(&v)), const int *); static_assert(*std::get_if(&v) == 42, ""); - static_assert(std::get_if(&v) == nullptr, ""); + static_assert(std::get_if(&v) == nullptr, ""); } { - using V = std::variant; + using V = std::variant; constexpr V v(42l); - ASSERT_SAME_TYPE(decltype(std::get_if(&v)), long const *); - static_assert(*std::get_if(&v) == 42, ""); + ASSERT_SAME_TYPE(decltype(std::get_if(&v)), const long *); + static_assert(*std::get_if(&v) == 42, ""); static_assert(std::get_if(&v) == nullptr, ""); } // FIXME: Remove these once reference support is reinstated @@ -77,18 +77,18 @@ void test_get_if() { assert(std::get_if(v) == nullptr); } { - using V = std::variant; + using V = std::variant; V v(42); ASSERT_NOEXCEPT(std::get_if(&v)); ASSERT_SAME_TYPE(decltype(std::get_if(&v)), int *); assert(*std::get_if(&v) == 42); - assert(std::get_if(&v) == nullptr); + assert(std::get_if(&v) == nullptr); } { - using V = std::variant; + using V = std::variant; V v(42l); - ASSERT_SAME_TYPE(decltype(std::get_if(&v)), long *); - assert(*std::get_if(&v) == 42); + ASSERT_SAME_TYPE(decltype(std::get_if(&v)), const long *); + assert(*std::get_if(&v) == 42); assert(std::get_if(&v) == nullptr); } // FIXME: Remove these once reference support is reinstated diff --git a/libcxx/test/std/utilities/variant/variant.get/get_index.pass.cpp b/libcxx/test/std/utilities/variant/variant.get/get_index.pass.cpp index 657db9b..669da53 100644 --- a/libcxx/test/std/utilities/variant/variant.get/get_index.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.get/get_index.pass.cpp @@ -34,16 +34,16 @@ void test_const_lvalue_get() { { - using V = std::variant; + using V = std::variant; constexpr V v(42); - // ASSERT_NOT_NOEXCEPT(std::get<0>(v)); - ASSERT_SAME_TYPE(decltype(std::get<0>(v)), int const &); + ASSERT_NOT_NOEXCEPT(std::get<0>(v)); + ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &); static_assert(std::get<0>(v) == 42, ""); } { - using V = std::variant; + using V = std::variant; constexpr V v(42l); - ASSERT_SAME_TYPE(decltype(std::get<1>(v)), long const &); + ASSERT_SAME_TYPE(decltype(std::get<1>(v)), const long &); static_assert(std::get<1>(v) == 42, ""); } // FIXME: Remove these once reference support is reinstated @@ -74,16 +74,16 @@ void test_const_lvalue_get() { void test_lvalue_get() { { - using V = std::variant; + using V = std::variant; V v(42); ASSERT_NOT_NOEXCEPT(std::get<0>(v)); ASSERT_SAME_TYPE(decltype(std::get<0>(v)), int &); assert(std::get<0>(v) == 42); } { - using V = std::variant; + using V = std::variant; V v(42l); - ASSERT_SAME_TYPE(decltype(std::get<1>(v)), long &); + ASSERT_SAME_TYPE(decltype(std::get<1>(v)), const long &); assert(std::get<1>(v) == 42); } // FIXME: Remove these once reference support is reinstated @@ -121,16 +121,16 @@ void test_lvalue_get() { void test_rvalue_get() { { - using V = std::variant; + using V = std::variant; V v(42); ASSERT_NOT_NOEXCEPT(std::get<0>(std::move(v))); ASSERT_SAME_TYPE(decltype(std::get<0>(std::move(v))), int &&); assert(std::get<0>(std::move(v)) == 42); } { - using V = std::variant; + using V = std::variant; V v(42l); - ASSERT_SAME_TYPE(decltype(std::get<1>(std::move(v))), long &&); + ASSERT_SAME_TYPE(decltype(std::get<1>(std::move(v))), const long &&); assert(std::get<1>(std::move(v)) == 42); } // FIXME: Remove these once reference support is reinstated @@ -170,14 +170,14 @@ void test_rvalue_get() { void test_const_rvalue_get() { { - using V = std::variant; + using V = std::variant; const V v(42); ASSERT_NOT_NOEXCEPT(std::get<0>(std::move(v))); ASSERT_SAME_TYPE(decltype(std::get<0>(std::move(v))), const int &&); assert(std::get<0>(std::move(v)) == 42); } { - using V = std::variant; + using V = std::variant; const V v(42l); ASSERT_SAME_TYPE(decltype(std::get<1>(std::move(v))), const long &&); assert(std::get<1>(std::move(v)) == 42); @@ -234,7 +234,7 @@ void test_throws_for_all_value_categories() { using Idx = decltype(idx); try { std::get(std::forward(v)); - } catch (std::bad_variant_access const &) { + } catch (const std::bad_variant_access &) { return true; } catch (...) { /* ... */ } diff --git a/libcxx/test/std/utilities/variant/variant.get/get_type.pass.cpp b/libcxx/test/std/utilities/variant/variant.get/get_type.pass.cpp index 11991dc..497f004 100644 --- a/libcxx/test/std/utilities/variant/variant.get/get_type.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.get/get_type.pass.cpp @@ -28,17 +28,17 @@ void test_const_lvalue_get() { { - using V = std::variant; + using V = std::variant; constexpr V v(42); - // ASSERT_NOT_NOEXCEPT(std::get(v)); - ASSERT_SAME_TYPE(decltype(std::get<0>(v)), int const &); + ASSERT_NOT_NOEXCEPT(std::get(v)); + ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &); static_assert(std::get(v) == 42, ""); } { - using V = std::variant; + using V = std::variant; constexpr V v(42l); - ASSERT_SAME_TYPE(decltype(std::get(v)), long const &); - static_assert(std::get(v) == 42, ""); + ASSERT_SAME_TYPE(decltype(std::get(v)), const long &); + static_assert(std::get(v) == 42, ""); } // FIXME: Remove these once reference support is reinstated #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) @@ -68,17 +68,17 @@ void test_const_lvalue_get() { void test_lvalue_get() { { - using V = std::variant; + using V = std::variant; V v(42); ASSERT_NOT_NOEXCEPT(std::get(v)); ASSERT_SAME_TYPE(decltype(std::get(v)), int &); assert(std::get(v) == 42); } { - using V = std::variant; + using V = std::variant; V v(42l); - ASSERT_SAME_TYPE(decltype(std::get(v)), long &); - assert(std::get(v) == 42); + ASSERT_SAME_TYPE(decltype(std::get(v)), const long &); + assert(std::get(v) == 42); } // FIXME: Remove these once reference support is reinstated #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) @@ -115,17 +115,18 @@ void test_lvalue_get() { void test_rvalue_get() { { - using V = std::variant; + using V = std::variant; V v(42); ASSERT_NOT_NOEXCEPT(std::get(std::move(v))); ASSERT_SAME_TYPE(decltype(std::get(std::move(v))), int &&); assert(std::get(std::move(v)) == 42); } { - using V = std::variant; + using V = std::variant; V v(42l); - ASSERT_SAME_TYPE(decltype(std::get(std::move(v))), long &&); - assert(std::get(std::move(v)) == 42); + ASSERT_SAME_TYPE(decltype(std::get(std::move(v))), + const long &&); + assert(std::get(std::move(v)) == 42); } // FIXME: Remove these once reference support is reinstated #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) @@ -166,17 +167,18 @@ void test_rvalue_get() { void test_const_rvalue_get() { { - using V = std::variant; + using V = std::variant; const V v(42); ASSERT_NOT_NOEXCEPT(std::get(std::move(v))); ASSERT_SAME_TYPE(decltype(std::get(std::move(v))), const int &&); assert(std::get(std::move(v)) == 42); } { - using V = std::variant; + using V = std::variant; const V v(42l); - ASSERT_SAME_TYPE(decltype(std::get(std::move(v))), const long &&); - assert(std::get(std::move(v)) == 42); + ASSERT_SAME_TYPE(decltype(std::get(std::move(v))), + const long &&); + assert(std::get(std::move(v)) == 42); } // FIXME: Remove these once reference support is reinstated #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) @@ -232,7 +234,7 @@ void test_throws_for_all_value_categories() { using Idx = decltype(idx); try { std::get(std::forward(v)); - } catch (std::bad_variant_access const &) { + } catch (const std::bad_variant_access &) { return true; } catch (...) { /* ... */ } diff --git a/libcxx/test/std/utilities/variant/variant.get/holds_alternative.pass.cpp b/libcxx/test/std/utilities/variant/variant.get/holds_alternative.pass.cpp index 3484386..103b049 100644 --- a/libcxx/test/std/utilities/variant/variant.get/holds_alternative.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.get/holds_alternative.pass.cpp @@ -15,6 +15,7 @@ // template // constexpr bool holds_alternative(const variant& v) noexcept; +#include "test_macros.h" #include int main() { @@ -32,6 +33,6 @@ int main() { { // noexcept test using V = std::variant; const V v; - static_assert(noexcept(std::holds_alternative(v)), "must be noexcept"); + ASSERT_NOEXCEPT(std::holds_alternative(v)); } } diff --git a/libcxx/test/std/utilities/variant/variant.hash/hash.pass.cpp b/libcxx/test/std/utilities/variant/variant.hash/hash.pass.cpp index df63989..1745508 100644 --- a/libcxx/test/std/utilities/variant/variant.hash/hash.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.hash/hash.pass.cpp @@ -25,7 +25,7 @@ #ifndef TEST_HAS_NO_EXCEPTIONS namespace std { template <> struct hash<::MakeEmptyT> { - size_t operator()(::MakeEmptyT const &) const { + size_t operator()(const ::MakeEmptyT &) const { assert(false); return 0; } @@ -40,7 +40,6 @@ void test_hash_variant() { const V v(std::in_place_index<0>, 42); const V v_copy = v; V v2(std::in_place_index<0>, 100); - const V v3(std::in_place_index<2>, 42); const H h{}; assert(h(v) == h(v)); assert(h(v) != h(v2)); diff --git a/libcxx/test/std/utilities/variant/variant.helpers/variant_alternative.pass.cpp b/libcxx/test/std/utilities/variant/variant.helpers/variant_alternative.pass.cpp index 1871c10..84689a0 100644 --- a/libcxx/test/std/utilities/variant/variant.helpers/variant_alternative.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.helpers/variant_alternative.pass.cpp @@ -66,10 +66,10 @@ int main() { } #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) { - using V = std::variant; + using V = std::variant; test(); test(); - test(); + test(); test(); test(); } diff --git a/libcxx/test/std/utilities/variant/variant.monostate.relops/relops.pass.cpp b/libcxx/test/std/utilities/variant/variant.monostate.relops/relops.pass.cpp index f430a66..49abba2 100644 --- a/libcxx/test/std/utilities/variant/variant.monostate.relops/relops.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.monostate.relops/relops.pass.cpp @@ -19,6 +19,7 @@ // constexpr bool operator==(monostate, monostate) noexcept { return true; } // constexpr bool operator!=(monostate, monostate) noexcept { return false; } +#include "test_macros.h" #include #include #include @@ -29,26 +30,26 @@ int main() { constexpr M m2{}; { static_assert((m1 < m2) == false, ""); - static_assert(noexcept(m1 < m2), ""); + ASSERT_NOEXCEPT(m1 < m2); } { static_assert((m1 > m2) == false, ""); - static_assert(noexcept(m1 > m2), ""); + ASSERT_NOEXCEPT(m1 > m2); } { static_assert((m1 <= m2) == true, ""); - static_assert(noexcept(m1 <= m2), ""); + ASSERT_NOEXCEPT(m1 <= m2); } { static_assert((m1 >= m2) == true, ""); - static_assert(noexcept(m1 >= m2), ""); + ASSERT_NOEXCEPT(m1 >= m2); } { static_assert((m1 == m2) == true, ""); - static_assert(noexcept(m1 == m2), ""); + ASSERT_NOEXCEPT(m1 == m2); } { static_assert((m1 != m2) == false, ""); - static_assert(noexcept(m1 != m2), ""); + ASSERT_NOEXCEPT(m1 != m2); } } diff --git a/libcxx/test/std/utilities/variant/variant.relops/relops.pass.cpp b/libcxx/test/std/utilities/variant/variant.relops/relops.pass.cpp index 51712ff..4337b4b 100644 --- a/libcxx/test/std/utilities/variant/variant.relops/relops.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.relops/relops.pass.cpp @@ -49,27 +49,27 @@ struct MakeEmptyT { MakeEmptyT(MakeEmptyT &&) { throw 42; } MakeEmptyT &operator=(MakeEmptyT &&) { throw 42; } }; -inline bool operator==(MakeEmptyT const &, MakeEmptyT const &) { +inline bool operator==(const MakeEmptyT &, const MakeEmptyT &) { assert(false); return false; } -inline bool operator!=(MakeEmptyT const &, MakeEmptyT const &) { +inline bool operator!=(const MakeEmptyT &, const MakeEmptyT &) { assert(false); return false; } -inline bool operator<(MakeEmptyT const &, MakeEmptyT const &) { +inline bool operator<(const MakeEmptyT &, const MakeEmptyT &) { assert(false); return false; } -inline bool operator<=(MakeEmptyT const &, MakeEmptyT const &) { +inline bool operator<=(const MakeEmptyT &, const MakeEmptyT &) { assert(false); return false; } -inline bool operator>(MakeEmptyT const &, MakeEmptyT const &) { +inline bool operator>(const MakeEmptyT &, const MakeEmptyT &) { assert(false); return false; } -inline bool operator>=(MakeEmptyT const &, MakeEmptyT const &) { +inline bool operator>=(const MakeEmptyT &, const MakeEmptyT &) { assert(false); return false; } @@ -158,7 +158,7 @@ void test_equality() { } template -constexpr bool test_less(Var const &l, Var const &r, bool expect_less, +constexpr bool test_less(const Var &l, const Var &r, bool expect_less, bool expect_greater) { return ((l < r) == expect_less) && (!(l >= r) == expect_less) && ((l > r) == expect_greater) && (!(l <= r) == expect_greater); diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp index 0a1d3c9..10022b1 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.assign/T.pass.cpp @@ -116,7 +116,7 @@ void test_T_assignment_sfinae() { static_assert(!std::is_assignable::value, "ambiguous"); } { - using V = std::variant; + using V = std::variant; static_assert(!std::is_assignable::value, "ambiguous"); } #endif @@ -149,9 +149,9 @@ void test_T_assignment_basic() { v = std::move(x); assert(v.index() == 1); assert(&std::get<1>(v) == &x); - // 'long' is selected by FUN(int const&) since 'int const&' cannot bind + // 'long' is selected by FUN(const int &) since 'const int &' cannot bind // to 'int&'. - int const &cx = x; + const int &cx = x; v = cx; assert(v.index() == 2); assert(std::get<2>(v) == 42); diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.assign/copy.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.assign/copy.pass.cpp index 65c2052..0e1a0cd 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.assign/copy.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.assign/copy.pass.cpp @@ -24,32 +24,32 @@ #include "test_macros.h" struct NoCopy { - NoCopy(NoCopy const &) = delete; - NoCopy &operator=(NoCopy const &) = default; + NoCopy(const NoCopy &) = delete; + NoCopy &operator=(const NoCopy &) = default; }; struct NothrowCopy { - NothrowCopy(NothrowCopy const &) noexcept = default; - NothrowCopy &operator=(NothrowCopy const &) noexcept = default; + NothrowCopy(const NothrowCopy &) noexcept = default; + NothrowCopy &operator=(const NothrowCopy &) noexcept = default; }; struct CopyOnly { - CopyOnly(CopyOnly const &) = default; + CopyOnly(const CopyOnly &) = default; CopyOnly(CopyOnly &&) = delete; - CopyOnly &operator=(CopyOnly const &) = default; + CopyOnly &operator=(const CopyOnly &) = default; CopyOnly &operator=(CopyOnly &&) = delete; }; struct MoveOnly { - MoveOnly(MoveOnly const &) = delete; + MoveOnly(const MoveOnly &) = delete; MoveOnly(MoveOnly &&) = default; - MoveOnly &operator=(MoveOnly const &) = default; + MoveOnly &operator=(const MoveOnly &) = default; }; struct MoveOnlyNT { - MoveOnlyNT(MoveOnlyNT const &) = delete; + MoveOnlyNT(const MoveOnlyNT &) = delete; MoveOnlyNT(MoveOnlyNT &&) {} - MoveOnlyNT &operator=(MoveOnlyNT const &) = default; + MoveOnlyNT &operator=(const MoveOnlyNT &) = default; }; struct CopyAssign { @@ -62,7 +62,7 @@ struct CopyAssign { copy_construct = copy_assign = move_construct = move_assign = alive = 0; } CopyAssign(int v) : value(v) { ++alive; } - CopyAssign(CopyAssign const &o) : value(o.value) { + CopyAssign(const CopyAssign &o) : value(o.value) { ++alive; ++copy_construct; } @@ -71,7 +71,7 @@ struct CopyAssign { ++alive; ++move_construct; } - CopyAssign &operator=(CopyAssign const &o) { + CopyAssign &operator=(const CopyAssign &o) { value = o.value; ++copy_assign; return *this; @@ -93,27 +93,27 @@ int CopyAssign::move_construct = 0; int CopyAssign::move_assign = 0; struct CopyMaybeThrows { - CopyMaybeThrows(CopyMaybeThrows const &); - CopyMaybeThrows &operator=(CopyMaybeThrows const &); + CopyMaybeThrows(const CopyMaybeThrows &); + CopyMaybeThrows &operator=(const CopyMaybeThrows &); }; struct CopyDoesThrow { - CopyDoesThrow(CopyDoesThrow const &) noexcept(false); - CopyDoesThrow &operator=(CopyDoesThrow const &) noexcept(false); + CopyDoesThrow(const CopyDoesThrow &) noexcept(false); + CopyDoesThrow &operator=(const CopyDoesThrow &) noexcept(false); }; #ifndef TEST_HAS_NO_EXCEPTIONS struct CopyThrows { CopyThrows() = default; - CopyThrows(CopyThrows const &) { throw 42; } - CopyThrows &operator=(CopyThrows const &) { throw 42; } + CopyThrows(const CopyThrows &) { throw 42; } + CopyThrows &operator=(const CopyThrows &) { throw 42; } }; struct MoveThrows { static int alive; MoveThrows() { ++alive; } - MoveThrows(MoveThrows const &) { ++alive; } + MoveThrows(const MoveThrows &) { ++alive; } MoveThrows(MoveThrows &&) { throw 42; } - MoveThrows &operator=(MoveThrows const &) { return *this; } + MoveThrows &operator=(const MoveThrows &) { return *this; } MoveThrows &operator=(MoveThrows &&) { throw 42; } ~MoveThrows() { --alive; } }; @@ -123,13 +123,13 @@ int MoveThrows::alive = 0; struct MakeEmptyT { static int alive; MakeEmptyT() { ++alive; } - MakeEmptyT(MakeEmptyT const &) { + MakeEmptyT(const MakeEmptyT &) { ++alive; // Don't throw from the copy constructor since variant's assignment // operator performs a copy before committing to the assignment. } MakeEmptyT(MakeEmptyT &&) { throw 42; } - MakeEmptyT &operator=(MakeEmptyT const &) { throw 42; } + MakeEmptyT &operator=(const MakeEmptyT &) { throw 42; } MakeEmptyT &operator=(MakeEmptyT &&) { throw 42; } ~MakeEmptyT() { --alive; } }; @@ -164,7 +164,7 @@ void test_copy_assignment_sfinae() { static_assert(std::is_copy_assignable::value, ""); } { - // variant only provides copy assignment when beth the copy and move + // variant only provides copy assignment when both the copy and move // constructors are well formed using V = std::variant; static_assert(!std::is_copy_assignable::value, ""); diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.assign/move.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.assign/move.pass.cpp index 0e07d13..f3dc815 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.assign/move.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.assign/move.pass.cpp @@ -26,36 +26,36 @@ #include "variant_test_helpers.hpp" struct NoCopy { - NoCopy(NoCopy const &) = delete; - NoCopy &operator=(NoCopy const &) = default; + NoCopy(const NoCopy &) = delete; + NoCopy &operator=(const NoCopy &) = default; }; struct CopyOnly { - CopyOnly(CopyOnly const &) = default; + CopyOnly(const CopyOnly &) = default; CopyOnly(CopyOnly &&) = delete; - CopyOnly &operator=(CopyOnly const &) = default; + CopyOnly &operator=(const CopyOnly &) = default; CopyOnly &operator=(CopyOnly &&) = delete; }; struct MoveOnly { - MoveOnly(MoveOnly const &) = delete; + MoveOnly(const MoveOnly &) = delete; MoveOnly(MoveOnly &&) = default; - MoveOnly &operator=(MoveOnly const &) = delete; + MoveOnly &operator=(const MoveOnly &) = delete; MoveOnly &operator=(MoveOnly &&) = default; }; struct MoveOnlyNT { - MoveOnlyNT(MoveOnlyNT const &) = delete; + MoveOnlyNT(const MoveOnlyNT &) = delete; MoveOnlyNT(MoveOnlyNT &&) {} - MoveOnlyNT &operator=(MoveOnlyNT const &) = delete; + MoveOnlyNT &operator=(const MoveOnlyNT &) = delete; MoveOnlyNT &operator=(MoveOnlyNT &&) = default; }; struct MoveOnlyOddNothrow { MoveOnlyOddNothrow(MoveOnlyOddNothrow &&) noexcept(false) {} - MoveOnlyOddNothrow(MoveOnlyOddNothrow const &) = delete; + MoveOnlyOddNothrow(const MoveOnlyOddNothrow &) = delete; MoveOnlyOddNothrow &operator=(MoveOnlyOddNothrow &&) noexcept = default; - MoveOnlyOddNothrow &operator=(MoveOnlyOddNothrow const &) = delete; + MoveOnlyOddNothrow &operator=(const MoveOnlyOddNothrow &) = delete; }; struct MoveAssignOnly { diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp index b9ea610..d33ea0b 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp @@ -68,7 +68,7 @@ void test_T_ctor_sfinae() { static_assert(!std::is_constructible::value, "ambiguous"); } { - using V = std::variant; + using V = std::variant; static_assert(!std::is_constructible::value, "ambiguous"); } #endif @@ -87,7 +87,7 @@ void test_T_ctor_basic() { } #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) { - using V = std::variant; + using V = std::variant; static_assert(std::is_convertible::value, "must be implicit"); int x = 42; V v(x); @@ -95,7 +95,7 @@ void test_T_ctor_basic() { assert(&std::get<0>(v) == &x); } { - using V = std::variant; + using V = std::variant; static_assert(std::is_convertible::value, "must be implicit"); int x = 42; V v(std::move(x)); diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp index 78fab62..18216c6 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp @@ -24,22 +24,22 @@ struct NonT { NonT(int v) : value(v) {} - NonT(NonT const &o) : value(o.value) {} + NonT(const NonT &o) : value(o.value) {} int value; }; static_assert(!std::is_trivially_copy_constructible::value, ""); struct NoCopy { - NoCopy(NoCopy const &) = delete; + NoCopy(const NoCopy &) = delete; }; struct MoveOnly { - MoveOnly(MoveOnly const &) = delete; + MoveOnly(const MoveOnly &) = delete; MoveOnly(MoveOnly &&) = default; }; struct MoveOnlyNT { - MoveOnlyNT(MoveOnlyNT const &) = delete; + MoveOnlyNT(const MoveOnlyNT &) = delete; MoveOnlyNT(MoveOnlyNT &&) {} }; @@ -47,13 +47,13 @@ struct MoveOnlyNT { struct MakeEmptyT { static int alive; MakeEmptyT() { ++alive; } - MakeEmptyT(MakeEmptyT const &) { + MakeEmptyT(const MakeEmptyT &) { ++alive; // Don't throw from the copy constructor since variant's assignment // operator performs a copy before committing to the assignment. } MakeEmptyT(MakeEmptyT &&) { throw 42; } - MakeEmptyT &operator=(MakeEmptyT const &) { throw 42; } + MakeEmptyT &operator=(const MakeEmptyT &) { throw 42; } MakeEmptyT &operator=(MakeEmptyT &&) { throw 42; } ~MakeEmptyT() { --alive; } }; @@ -124,7 +124,7 @@ void test_copy_ctor_valueless_by_exception() { using V = std::variant; V v1; makeEmpty(v1); - V const &cv1 = v1; + const V &cv1 = v1; V v(cv1); assert(v.valueless_by_exception()); #endif diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/default.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/default.pass.cpp index 124260b..a4a86ff 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/default.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/default.pass.cpp @@ -71,7 +71,7 @@ void test_default_ctor_throws() { try { V v; assert(false); - } catch (int const &ex) { + } catch (const int &ex) { assert(ex == 42); } catch (...) { assert(false); diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp index 2a87f32..66f67fe 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp @@ -28,20 +28,20 @@ struct ThrowsMove { }; struct NoCopy { - NoCopy(NoCopy const &) = delete; + NoCopy(const NoCopy &) = delete; }; struct MoveOnly { int value; MoveOnly(int v) : value(v) {} - MoveOnly(MoveOnly const &) = delete; + MoveOnly(const MoveOnly &) = delete; MoveOnly(MoveOnly &&) = default; }; struct MoveOnlyNT { int value; MoveOnlyNT(int v) : value(v) {} - MoveOnlyNT(MoveOnlyNT const &) = delete; + MoveOnlyNT(const MoveOnlyNT &) = delete; MoveOnlyNT(MoveOnlyNT &&other) : value(other.value) { other.value = -1; } }; @@ -49,13 +49,13 @@ struct MoveOnlyNT { struct MakeEmptyT { static int alive; MakeEmptyT() { ++alive; } - MakeEmptyT(MakeEmptyT const &) { + MakeEmptyT(const MakeEmptyT &) { ++alive; // Don't throw from the copy constructor since variant's assignment // operator performs a copy before committing to the assignment. } MakeEmptyT(MakeEmptyT &&) { throw 42; } - MakeEmptyT &operator=(MakeEmptyT const &) { throw 42; } + MakeEmptyT &operator=(const MakeEmptyT &) { throw 42; } MakeEmptyT &operator=(MakeEmptyT &&) { throw 42; } ~MakeEmptyT() { --alive; } }; diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.dtor/dtor.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.dtor/dtor.pass.cpp index 8e36a8a..7299394 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.dtor/dtor.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.dtor/dtor.pass.cpp @@ -39,7 +39,7 @@ int NonTDtor1::count = 0; static_assert(!std::is_trivially_destructible::value, ""); struct TDtor { - TDtor(TDtor const &) {} // non-trivial copy + TDtor(const TDtor &) {} // non-trivial copy ~TDtor() = default; }; static_assert(!std::is_trivially_copy_constructible::value, ""); diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_args.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_args.pass.cpp index 4dae324..8f694cf 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_args.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_args.pass.cpp @@ -58,14 +58,14 @@ void test_emplace_sfinae() { } #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) { - using V = std::variant; + using V = std::variant; static_assert(emplace_exists(), ""); static_assert(emplace_exists(), ""); static_assert(emplace_exists(), ""); static_assert(!emplace_exists(), "too many args"); static_assert(emplace_exists(), ""); static_assert(!emplace_exists(), "cannot default construct ref"); - static_assert(!emplace_exists(), "cannot bind ref"); + static_assert(!emplace_exists(), "cannot bind ref"); static_assert(!emplace_exists(), "cannot bind ref"); static_assert(emplace_exists(), ""); static_assert(emplace_exists(), ""); @@ -74,8 +74,8 @@ void test_emplace_sfinae() { "not constructible from void*"); static_assert(emplace_exists(), ""); static_assert(!emplace_exists(), "cannot bind ref"); - static_assert(!emplace_exists(), "cannot bind ref"); - static_assert(!emplace_exists(), "cannot bind ref"); + static_assert(!emplace_exists(), "cannot bind ref"); + static_assert(!emplace_exists(), "cannot bind ref"); static_assert(!emplace_exists(), "no ctors"); } #endif @@ -106,7 +106,7 @@ void test_basic() { } #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) { - using V = std::variant; const int x = 100; int y = 42; diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp index 53a030d..4ca2cc4 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp @@ -52,12 +52,12 @@ void test_emplace_sfinae() { static_assert(!emplace_exists(), "cannot construct"); static_assert(emplace_exists(), ""); static_assert(!emplace_exists(), ""); - static_assert(emplace_exists(), ""); - static_assert(emplace_exists(), ""); + static_assert(emplace_exists(), ""); + static_assert(emplace_exists(), ""); static_assert(!emplace_exists(), "cannot construct"); } #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) - using V = std::variant; static_assert(emplace_exists(), ""); static_assert(emplace_exists(), ""); @@ -65,17 +65,17 @@ void test_emplace_sfinae() { static_assert(!emplace_exists(), "too many args"); static_assert(emplace_exists(), ""); static_assert(!emplace_exists(), "cannot default construct ref"); - static_assert(!emplace_exists(), "cannot bind ref"); + static_assert(!emplace_exists(), "cannot bind ref"); static_assert(!emplace_exists(), "cannot bind ref"); - static_assert(emplace_exists(), ""); - static_assert(emplace_exists(), ""); - static_assert(emplace_exists(), ""); - static_assert(!emplace_exists(), + static_assert(emplace_exists(), ""); + static_assert(emplace_exists(), ""); + static_assert(emplace_exists(), ""); + static_assert(!emplace_exists(), "not constructible from void*"); static_assert(emplace_exists(), ""); static_assert(!emplace_exists(), "cannot bind ref"); - static_assert(!emplace_exists(), "cannot bind ref"); - static_assert(!emplace_exists(), "cannot bind ref"); + static_assert(!emplace_exists(), "cannot bind ref"); + static_assert(!emplace_exists(), "cannot bind ref"); static_assert(!emplace_exists(), "ambiguous"); static_assert(!emplace_exists(), "cannot construct void"); @@ -107,7 +107,7 @@ void test_basic() { } #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) { - using V = std::variant; const int x = 100; int y = 42; @@ -117,8 +117,8 @@ void test_basic() { v.emplace(); assert(std::get(v) == 0); // emplace a reference - v.emplace(x); - assert(&std::get(v) == &x); + v.emplace(x); + assert(&std::get(v) == &x); // emplace an rvalue reference v.emplace(std::move(y)); assert(&std::get(v) == &y); diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.swap/swap.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.swap/swap.pass.cpp index 1fb5c72..416c6b4 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.swap/swap.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.swap/swap.pass.cpp @@ -30,14 +30,14 @@ void swap(NotSwappable &, NotSwappable &) = delete; struct NotCopyable { NotCopyable() = default; - NotCopyable(NotCopyable const &) = delete; - NotCopyable &operator=(NotCopyable const &) = delete; + NotCopyable(const NotCopyable &) = delete; + NotCopyable &operator=(const NotCopyable &) = delete; }; struct NotCopyableWithSwap { NotCopyableWithSwap() = default; - NotCopyableWithSwap(NotCopyableWithSwap const &) = delete; - NotCopyableWithSwap &operator=(NotCopyableWithSwap const &) = delete; + NotCopyableWithSwap(const NotCopyableWithSwap &) = delete; + NotCopyableWithSwap &operator=(const NotCopyableWithSwap &) = delete; }; void swap(NotCopyableWithSwap &, NotCopyableWithSwap) {} @@ -73,7 +73,7 @@ struct NothrowTypeImp { static void reset() { move_called = move_assign_called = swap_called = 0; } NothrowTypeImp() = default; explicit NothrowTypeImp(int v) : value(v) {} - NothrowTypeImp(NothrowTypeImp const &o) noexcept(NT_Copy) : value(o.value) { + NothrowTypeImp(const NothrowTypeImp &o) noexcept(NT_Copy) : value(o.value) { assert(false); } // never called by test NothrowTypeImp(NothrowTypeImp &&o) noexcept(NT_Move) : value(o.value) { @@ -81,7 +81,7 @@ struct NothrowTypeImp { do_throw(); o.value = -1; } - NothrowTypeImp &operator=(NothrowTypeImp const &) noexcept(NT_CopyAssign) { + NothrowTypeImp &operator=(const NothrowTypeImp &) noexcept(NT_CopyAssign) { assert(false); return *this; } // never called by the tests diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant_reference.fail.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant_reference.fail.cpp index 1e5b927..bda27f0 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant_reference.fail.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant_reference.fail.cpp @@ -23,6 +23,6 @@ int main() { // expected-error@variant:* 3 {{static_assert failed}} std::variant v; // expected-note {{requested here}} - std::variant v2; // expected-note {{requested here}} + std::variant v2; // expected-note {{requested here}} std::variant v3; // expected-note {{requested here}} } diff --git a/libcxx/test/std/utilities/variant/variant.visit/visit.pass.cpp b/libcxx/test/std/utilities/variant/variant.visit/visit.pass.cpp index 1783fe9..46d2258 100644 --- a/libcxx/test/std/utilities/variant/variant.visit/visit.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.visit/visit.pass.cpp @@ -77,16 +77,16 @@ struct ForwardingCallObject { } static CallType last_call_type; - static TypeID const *last_call_args; + static const TypeID *last_call_args; }; CallType ForwardingCallObject::last_call_type = CT_None; -TypeID const *ForwardingCallObject::last_call_args = nullptr; +const TypeID *ForwardingCallObject::last_call_args = nullptr; void test_call_operator_forwarding() { using Fn = ForwardingCallObject; Fn obj{}; - Fn const &cobj = obj; + const Fn &cobj = obj; { // test call operator forwarding - single variant, single arg using V = std::variant; V v(42); @@ -134,11 +134,11 @@ void test_argument_forwarding() { { // single argument - value type using V = std::variant; V v(42); - V const &cv = v; + const V &cv = v; std::visit(obj, v); assert(Fn::check_call(Val)); std::visit(obj, cv); - assert(Fn::check_call(Val)); + assert(Fn::check_call(Val)); std::visit(obj, std::move(v)); assert(Fn::check_call(Val)); std::visit(obj, std::move(cv)); @@ -149,7 +149,7 @@ void test_argument_forwarding() { using V = std::variant; int x = 42; V v(x); - V const &cv = v; + const V &cv = v; std::visit(obj, v); assert(Fn::check_call(Val)); std::visit(obj, cv); @@ -163,7 +163,7 @@ void test_argument_forwarding() { using V = std::variant; int x = 42; V v(std::move(x)); - V const &cv = v; + const V &cv = v; std::visit(obj, v); assert(Fn::check_call(Val)); std::visit(obj, cv); @@ -174,16 +174,16 @@ void test_argument_forwarding() { assert(Fn::check_call(Val)); } { // multi argument - multi variant - using S = std::string const &; + using S = const std::string &; using V = std::variant; - std::string const str = "hello"; + const std::string str = "hello"; long l = 43; V v1(42); - V const &cv1 = v1; + const V &cv1 = v1; V v2(str); - V const &cv2 = v2; + const V &cv2 = v2; V v3(std::move(l)); - V const &cv3 = v3; + const V &cv3 = v3; std::visit(obj, v1, v2, v3); assert((Fn::check_call(Val))); std::visit(obj, cv1, cv2, std::move(v3)); @@ -243,7 +243,7 @@ void test_exceptions() { auto test = [&](auto &&... args) { try { std::visit(obj, args...); - } catch (std::bad_variant_access const &) { + } catch (const std::bad_variant_access &) { return true; } catch (...) { } -- 2.7.4