[libcxx-commits] [libcxx] 321c2ea - [libc++][NFC] Move monostate to its own header.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jul 8 08:35:40 PDT 2021
Author: Mark de Wever
Date: 2021-07-08T17:35:26+02:00
New Revision: 321c2ea91cb1aed5dfbbdbb868d525ff64972398
URL: https://github.com/llvm/llvm-project/commit/321c2ea91cb1aed5dfbbdbb868d525ff64972398
DIFF: https://github.com/llvm/llvm-project/commit/321c2ea91cb1aed5dfbbdbb868d525ff64972398.diff
LOG: [libc++][NFC] Move monostate to its own header.
The format library uses `std::monostate`, but not a `std::variant`.
Moving `std::monostate` to its own header allows the format library to
reduce the amount of included code.
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D105582
Added:
libcxx/include/__variant/monostate.h
Modified:
libcxx/include/CMakeLists.txt
libcxx/include/module.modulemap
libcxx/include/variant
Removed:
################################################################################
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index a1d5374c30a9c..b9c585dbf1aae 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -237,6 +237,7 @@ set(files
__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
index 0000000000000..36e3eead1a476
--- /dev/null
+++ b/libcxx/include/__variant/monostate.h
@@ -0,0 +1,65 @@
+// -*- 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 <cstddef>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER > 14
+
+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<monostate> {
+ 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
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___VARIANT_MONOSTATE_H
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index eb4488b6342a4..c2e6564bb1247 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -735,6 +735,10 @@ module std [system] {
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
index 2145700e5a68a..08b64612d133c 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -202,6 +202,7 @@ namespace std {
#include <__availability>
#include <__config>
#include <__utility/forward.h>
+#include <__variant/monostate.h>
#include <__tuple>
#include <array>
#include <compare>
@@ -1703,26 +1704,6 @@ inline _LIBCPP_INLINE_VISIBILITY
}
#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 <class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
auto swap(variant<_Types...>& __lhs,
@@ -1755,17 +1736,6 @@ struct _LIBCPP_TEMPLATE_VIS hash<
}
};
-template <>
-struct _LIBCPP_TEMPLATE_VIS hash<monostate> {
- 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
More information about the libcxx-commits
mailing list