diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -237,6 +237,7 @@ __utility/rel_ops.h __utility/swap.h __utility/to_underlying.h + __variant/monostate.h algorithm any array diff --git a/libcxx/include/__variant/monostate.h b/libcxx/include/__variant/monostate.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__variant/monostate.h @@ -0,0 +1,61 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___VARIANT_MONOSTATE_H +#define _LIBCPP___VARIANT_MONOSTATE_H + +#include <__config> +#include <__functional/hash.h> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct _LIBCPP_TEMPLATE_VIS 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 <> +struct _LIBCPP_TEMPLATE_VIS hash { + using argument_type = monostate; + using result_type = size_t; + + inline _LIBCPP_INLINE_VISIBILITY + result_type operator()(const argument_type&) const _NOEXCEPT { + return 66740831; // return a fundamentally attractive random value. + } +}; + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___VARIANT_MONOSTATE_H diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap --- a/libcxx/include/module.modulemap +++ b/libcxx/include/module.modulemap @@ -735,6 +735,10 @@ module variant { header "variant" export * + + module __variant { + module monostate { header "__variant/monostate.h" } + } } module vector { header "vector" diff --git a/libcxx/include/variant b/libcxx/include/variant --- a/libcxx/include/variant +++ b/libcxx/include/variant @@ -202,6 +202,7 @@ #include <__availability> #include <__config> #include <__utility/forward.h> +#include <__variant/monostate.h> #include <__tuple> #include #include @@ -1703,26 +1704,6 @@ } #endif -struct _LIBCPP_TEMPLATE_VIS 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, @@ -1755,17 +1736,6 @@ } }; -template <> -struct _LIBCPP_TEMPLATE_VIS hash { - using argument_type = monostate; - using result_type = size_t; - - inline _LIBCPP_INLINE_VISIBILITY - result_type operator()(const argument_type&) const _NOEXCEPT { - return 66740831; // return a fundamentally attractive random value. - } -}; - #endif // _LIBCPP_STD_VER > 14 _LIBCPP_END_NAMESPACE_STD