// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef BASE_TYPES_EXPECTED_INTERNAL_H_ #define BASE_TYPES_EXPECTED_INTERNAL_H_ // IWYU pragma: private, include "base/types/expected.h" #include <concepts> #include <functional> #include <type_traits> #include <utility> #include "base/check.h" #include "third_party/abseil-cpp/absl/types/variant.h" #include "third_party/abseil-cpp/absl/utility/utility.h" // This header defines type traits and aliases used for the implementation of // base::expected. namespace base { template <typename T> class ok; template <typename E> class unexpected; struct unexpect_t { … }; // in-place construction of unexpected values inline constexpr unexpect_t unexpect{ … }; template <typename T, typename E> class expected; namespace internal { UnderlyingIsOk; UnderlyingIsOk; IsOk; UnderlyingIsUnexpected; UnderlyingIsUnexpected; IsUnexpected; UnderlyingIsExpected; UnderlyingIsExpected; IsExpected; IsConstructibleOrConvertible; IsAnyConstructibleOrConvertible; // Checks whether a given expected<U, G> can be converted into another // expected<T, E>. Used inside expected's conversion constructors. UF and GF are // the forwarded versions of U and G, e.g. UF is const U& for the converting // copy constructor and U for the converting move constructor. Similarly for GF. // ExUG is used for convenience, and not expected to be passed explicitly. // See https://eel.is/c++draft/expected#lib:expected,constructor___ IsValidConversion; // Checks whether a given expected<U, G> can be converted into another // expected<T, E> when T is a void type. Used inside expected<void>'s conversion // constructors. GF is the forwarded versions of G, e.g. GF is const G& for the // converting copy constructor and G for the converting move constructor. ExUG // is used for convenience, and not expected to be passed explicitly. See // https://eel.is/c++draft/expected#lib:expected%3cvoid%3e,constructor___ IsValidVoidConversion; // Checks whether expected<T, E> can be constructed from a value of type U. IsValidValueConstruction; IsOkValueConstruction; IsUnexpectedValueConstruction; IsValueAssignment; template <typename T, typename E> class ExpectedImpl { … }; template <typename Exp, typename F> constexpr auto AndThen(Exp&& exp, F&& f) noexcept { … } template <typename Exp, typename F> constexpr auto OrElse(Exp&& exp, F&& f) noexcept { … } template <typename Exp, typename F> constexpr auto Transform(Exp&& exp, F&& f) noexcept { … } template <typename Exp, typename F> constexpr auto TransformError(Exp&& exp, F&& f) noexcept { … } } // namespace internal } // namespace base #endif // BASE_TYPES_EXPECTED_INTERNAL_H_