diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/libs/llvm12/include/llvm/ADT/Optional.h | |
parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
download | ydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/llvm12/include/llvm/ADT/Optional.h')
-rw-r--r-- | contrib/libs/llvm12/include/llvm/ADT/Optional.h | 214 |
1 files changed, 107 insertions, 107 deletions
diff --git a/contrib/libs/llvm12/include/llvm/ADT/Optional.h b/contrib/libs/llvm12/include/llvm/ADT/Optional.h index e3d9ea6eef..0f0725c73e 100644 --- a/contrib/libs/llvm12/include/llvm/ADT/Optional.h +++ b/contrib/libs/llvm12/include/llvm/ADT/Optional.h @@ -22,7 +22,7 @@ #ifndef LLVM_ADT_OPTIONAL_H #define LLVM_ADT_OPTIONAL_H -#include "llvm/ADT/Hashing.h" +#include "llvm/ADT/Hashing.h" #include "llvm/ADT/None.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/type_traits.h" @@ -40,30 +40,30 @@ namespace optional_detail { struct in_place_t {}; /// Storage for any type. -// -// The specialization condition intentionally uses -// llvm::is_trivially_copy_constructible instead of -// std::is_trivially_copy_constructible. GCC versions prior to 7.4 may -// instantiate the copy constructor of `T` when -// std::is_trivially_copy_constructible is instantiated. This causes -// compilation to fail if we query the trivially copy constructible property of -// a class which is not copy constructible. -// -// The current implementation of OptionalStorage insists that in order to use -// the trivial specialization, the value_type must be trivially copy -// constructible and trivially copy assignable due to =default implementations -// of the copy/move constructor/assignment. It does not follow that this is -// necessarily the case std::is_trivially_copyable is true (hence the expanded -// specialization condition). -// -// The move constructible / assignable conditions emulate the remaining behavior -// of std::is_trivially_copyable. -template <typename T, bool = (llvm::is_trivially_copy_constructible<T>::value && - std::is_trivially_copy_assignable<T>::value && - (std::is_trivially_move_constructible<T>::value || - !std::is_move_constructible<T>::value) && - (std::is_trivially_move_assignable<T>::value || - !std::is_move_assignable<T>::value))> +// +// The specialization condition intentionally uses +// llvm::is_trivially_copy_constructible instead of +// std::is_trivially_copy_constructible. GCC versions prior to 7.4 may +// instantiate the copy constructor of `T` when +// std::is_trivially_copy_constructible is instantiated. This causes +// compilation to fail if we query the trivially copy constructible property of +// a class which is not copy constructible. +// +// The current implementation of OptionalStorage insists that in order to use +// the trivial specialization, the value_type must be trivially copy +// constructible and trivially copy assignable due to =default implementations +// of the copy/move constructor/assignment. It does not follow that this is +// necessarily the case std::is_trivially_copyable is true (hence the expanded +// specialization condition). +// +// The move constructible / assignable conditions emulate the remaining behavior +// of std::is_trivially_copyable. +template <typename T, bool = (llvm::is_trivially_copy_constructible<T>::value && + std::is_trivially_copy_assignable<T>::value && + (std::is_trivially_move_constructible<T>::value || + !std::is_move_constructible<T>::value) && + (std::is_trivially_move_assignable<T>::value || + !std::is_move_assignable<T>::value))> class OptionalStorage { union { char empty; @@ -74,21 +74,21 @@ class OptionalStorage { public: ~OptionalStorage() { reset(); } - constexpr OptionalStorage() noexcept : empty(), hasVal(false) {} + constexpr OptionalStorage() noexcept : empty(), hasVal(false) {} - constexpr OptionalStorage(OptionalStorage const &other) : OptionalStorage() { + constexpr OptionalStorage(OptionalStorage const &other) : OptionalStorage() { if (other.hasValue()) { emplace(other.value); } } - constexpr OptionalStorage(OptionalStorage &&other) : OptionalStorage() { + constexpr OptionalStorage(OptionalStorage &&other) : OptionalStorage() { if (other.hasValue()) { emplace(std::move(other.value)); } } template <class... Args> - constexpr explicit OptionalStorage(in_place_t, Args &&... args) + constexpr explicit OptionalStorage(in_place_t, Args &&... args) : value(std::forward<Args>(args)...), hasVal(true) {} void reset() noexcept { @@ -98,13 +98,13 @@ public: } } - constexpr bool hasValue() const noexcept { return hasVal; } + constexpr bool hasValue() const noexcept { return hasVal; } T &getValue() LLVM_LVALUE_FUNCTION noexcept { assert(hasVal); return value; } - constexpr T const &getValue() const LLVM_LVALUE_FUNCTION noexcept { + constexpr T const &getValue() const LLVM_LVALUE_FUNCTION noexcept { assert(hasVal); return value; } @@ -179,16 +179,16 @@ template <typename T> class OptionalStorage<T, true> { public: ~OptionalStorage() = default; - constexpr OptionalStorage() noexcept : empty{} {} + constexpr OptionalStorage() noexcept : empty{} {} - constexpr OptionalStorage(OptionalStorage const &other) = default; - constexpr OptionalStorage(OptionalStorage &&other) = default; + constexpr OptionalStorage(OptionalStorage const &other) = default; + constexpr OptionalStorage(OptionalStorage &&other) = default; OptionalStorage &operator=(OptionalStorage const &other) = default; OptionalStorage &operator=(OptionalStorage &&other) = default; template <class... Args> - constexpr explicit OptionalStorage(in_place_t, Args &&... args) + constexpr explicit OptionalStorage(in_place_t, Args &&... args) : value(std::forward<Args>(args)...), hasVal(true) {} void reset() noexcept { @@ -198,13 +198,13 @@ public: } } - constexpr bool hasValue() const noexcept { return hasVal; } + constexpr bool hasValue() const noexcept { return hasVal; } T &getValue() LLVM_LVALUE_FUNCTION noexcept { assert(hasVal); return value; } - constexpr T const &getValue() const LLVM_LVALUE_FUNCTION noexcept { + constexpr T const &getValue() const LLVM_LVALUE_FUNCTION noexcept { assert(hasVal); return value; } @@ -252,12 +252,12 @@ public: constexpr Optional() {} constexpr Optional(NoneType) {} - constexpr Optional(const T &y) : Storage(optional_detail::in_place_t{}, y) {} - constexpr Optional(const Optional &O) = default; + constexpr Optional(const T &y) : Storage(optional_detail::in_place_t{}, y) {} + constexpr Optional(const Optional &O) = default; - constexpr Optional(T &&y) - : Storage(optional_detail::in_place_t{}, std::move(y)) {} - constexpr Optional(Optional &&O) = default; + constexpr Optional(T &&y) + : Storage(optional_detail::in_place_t{}, std::move(y)) {} + constexpr Optional(Optional &&O) = default; Optional &operator=(T &&y) { Storage = std::move(y); @@ -270,7 +270,7 @@ public: Storage.emplace(std::forward<ArgTypes>(Args)...); } - static constexpr Optional create(const T *y) { + static constexpr Optional create(const T *y) { return y ? Optional(*y) : Optional(); } @@ -282,20 +282,20 @@ public: void reset() { Storage.reset(); } - constexpr const T *getPointer() const { return &Storage.getValue(); } + constexpr const T *getPointer() const { return &Storage.getValue(); } T *getPointer() { return &Storage.getValue(); } - constexpr const T &getValue() const LLVM_LVALUE_FUNCTION { - return Storage.getValue(); - } + constexpr const T &getValue() const LLVM_LVALUE_FUNCTION { + return Storage.getValue(); + } T &getValue() LLVM_LVALUE_FUNCTION { return Storage.getValue(); } - constexpr explicit operator bool() const { return hasValue(); } - constexpr bool hasValue() const { return Storage.hasValue(); } - constexpr const T *operator->() const { return getPointer(); } + constexpr explicit operator bool() const { return hasValue(); } + constexpr bool hasValue() const { return Storage.hasValue(); } + constexpr const T *operator->() const { return getPointer(); } T *operator->() { return getPointer(); } - constexpr const T &operator*() const LLVM_LVALUE_FUNCTION { - return getValue(); - } + constexpr const T &operator*() const LLVM_LVALUE_FUNCTION { + return getValue(); + } T &operator*() LLVM_LVALUE_FUNCTION { return getValue(); } template <typename U> @@ -330,157 +330,157 @@ public: #endif }; -template <class T> llvm::hash_code hash_value(const Optional<T> &O) { - return O ? hash_combine(true, *O) : hash_value(false); -} - +template <class T> llvm::hash_code hash_value(const Optional<T> &O) { + return O ? hash_combine(true, *O) : hash_value(false); +} + template <typename T, typename U> -constexpr bool operator==(const Optional<T> &X, const Optional<U> &Y) { +constexpr bool operator==(const Optional<T> &X, const Optional<U> &Y) { if (X && Y) return *X == *Y; return X.hasValue() == Y.hasValue(); } template <typename T, typename U> -constexpr bool operator!=(const Optional<T> &X, const Optional<U> &Y) { +constexpr bool operator!=(const Optional<T> &X, const Optional<U> &Y) { return !(X == Y); } template <typename T, typename U> -constexpr bool operator<(const Optional<T> &X, const Optional<U> &Y) { +constexpr bool operator<(const Optional<T> &X, const Optional<U> &Y) { if (X && Y) return *X < *Y; return X.hasValue() < Y.hasValue(); } template <typename T, typename U> -constexpr bool operator<=(const Optional<T> &X, const Optional<U> &Y) { +constexpr bool operator<=(const Optional<T> &X, const Optional<U> &Y) { return !(Y < X); } template <typename T, typename U> -constexpr bool operator>(const Optional<T> &X, const Optional<U> &Y) { +constexpr bool operator>(const Optional<T> &X, const Optional<U> &Y) { return Y < X; } template <typename T, typename U> -constexpr bool operator>=(const Optional<T> &X, const Optional<U> &Y) { +constexpr bool operator>=(const Optional<T> &X, const Optional<U> &Y) { return !(X < Y); } -template <typename T> -constexpr bool operator==(const Optional<T> &X, NoneType) { +template <typename T> +constexpr bool operator==(const Optional<T> &X, NoneType) { return !X; } -template <typename T> -constexpr bool operator==(NoneType, const Optional<T> &X) { +template <typename T> +constexpr bool operator==(NoneType, const Optional<T> &X) { return X == None; } -template <typename T> -constexpr bool operator!=(const Optional<T> &X, NoneType) { +template <typename T> +constexpr bool operator!=(const Optional<T> &X, NoneType) { return !(X == None); } -template <typename T> -constexpr bool operator!=(NoneType, const Optional<T> &X) { +template <typename T> +constexpr bool operator!=(NoneType, const Optional<T> &X) { return X != None; } -template <typename T> constexpr bool operator<(const Optional<T> &X, NoneType) { +template <typename T> constexpr bool operator<(const Optional<T> &X, NoneType) { return false; } -template <typename T> constexpr bool operator<(NoneType, const Optional<T> &X) { +template <typename T> constexpr bool operator<(NoneType, const Optional<T> &X) { return X.hasValue(); } -template <typename T> -constexpr bool operator<=(const Optional<T> &X, NoneType) { +template <typename T> +constexpr bool operator<=(const Optional<T> &X, NoneType) { return !(None < X); } -template <typename T> -constexpr bool operator<=(NoneType, const Optional<T> &X) { +template <typename T> +constexpr bool operator<=(NoneType, const Optional<T> &X) { return !(X < None); } -template <typename T> constexpr bool operator>(const Optional<T> &X, NoneType) { +template <typename T> constexpr bool operator>(const Optional<T> &X, NoneType) { return None < X; } -template <typename T> constexpr bool operator>(NoneType, const Optional<T> &X) { +template <typename T> constexpr bool operator>(NoneType, const Optional<T> &X) { return X < None; } -template <typename T> -constexpr bool operator>=(const Optional<T> &X, NoneType) { +template <typename T> +constexpr bool operator>=(const Optional<T> &X, NoneType) { return None <= X; } -template <typename T> -constexpr bool operator>=(NoneType, const Optional<T> &X) { +template <typename T> +constexpr bool operator>=(NoneType, const Optional<T> &X) { return X <= None; } -template <typename T> -constexpr bool operator==(const Optional<T> &X, const T &Y) { +template <typename T> +constexpr bool operator==(const Optional<T> &X, const T &Y) { return X && *X == Y; } -template <typename T> -constexpr bool operator==(const T &X, const Optional<T> &Y) { +template <typename T> +constexpr bool operator==(const T &X, const Optional<T> &Y) { return Y && X == *Y; } -template <typename T> -constexpr bool operator!=(const Optional<T> &X, const T &Y) { +template <typename T> +constexpr bool operator!=(const Optional<T> &X, const T &Y) { return !(X == Y); } -template <typename T> -constexpr bool operator!=(const T &X, const Optional<T> &Y) { +template <typename T> +constexpr bool operator!=(const T &X, const Optional<T> &Y) { return !(X == Y); } -template <typename T> -constexpr bool operator<(const Optional<T> &X, const T &Y) { +template <typename T> +constexpr bool operator<(const Optional<T> &X, const T &Y) { return !X || *X < Y; } -template <typename T> -constexpr bool operator<(const T &X, const Optional<T> &Y) { +template <typename T> +constexpr bool operator<(const T &X, const Optional<T> &Y) { return Y && X < *Y; } -template <typename T> -constexpr bool operator<=(const Optional<T> &X, const T &Y) { +template <typename T> +constexpr bool operator<=(const Optional<T> &X, const T &Y) { return !(Y < X); } -template <typename T> -constexpr bool operator<=(const T &X, const Optional<T> &Y) { +template <typename T> +constexpr bool operator<=(const T &X, const Optional<T> &Y) { return !(Y < X); } -template <typename T> -constexpr bool operator>(const Optional<T> &X, const T &Y) { +template <typename T> +constexpr bool operator>(const Optional<T> &X, const T &Y) { return Y < X; } -template <typename T> -constexpr bool operator>(const T &X, const Optional<T> &Y) { +template <typename T> +constexpr bool operator>(const T &X, const Optional<T> &Y) { return Y < X; } -template <typename T> -constexpr bool operator>=(const Optional<T> &X, const T &Y) { +template <typename T> +constexpr bool operator>=(const Optional<T> &X, const T &Y) { return !(X < Y); } -template <typename T> -constexpr bool operator>=(const T &X, const Optional<T> &Y) { +template <typename T> +constexpr bool operator>=(const T &X, const Optional<T> &Y) { return !(X < Y); } |