forked from OSchip/llvm-project
[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
This commit is contained in:
parent
4947ecf4e9
commit
321c2ea91c
|
@ -237,6 +237,7 @@ set(files
|
|||
__utility/rel_ops.h
|
||||
__utility/swap.h
|
||||
__utility/to_underlying.h
|
||||
__variant/monostate.h
|
||||
algorithm
|
||||
any
|
||||
array
|
||||
|
|
|
@ -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
|
|
@ -735,6 +735,10 @@ module std [system] {
|
|||
module variant {
|
||||
header "variant"
|
||||
export *
|
||||
|
||||
module __variant {
|
||||
module monostate { header "__variant/monostate.h" }
|
||||
}
|
||||
}
|
||||
module vector {
|
||||
header "vector"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue