Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
unexpected.h171 linesDownload Raw Back to __expected
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES.7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCUDACXX___EXPECTED_UNEXPECTED_H11#define _LIBCUDACXX___EXPECTED_UNEXPECTED_H12 13#ifndef __cuda_std__14#include <__config>15#endif // __cuda_std__16 17#include "../__concepts/__concept_macros.h"18#include "../__type_traits/integral_constant.h"19#include "../__type_traits/is_array.h"20#include "../__type_traits/is_const.h"21#include "../__type_traits/is_constructible.h"22#include "../__type_traits/is_nothrow_constructible.h"23#include "../__type_traits/is_object.h"24#include "../__type_traits/is_same.h"25#include "../__type_traits/is_swappable.h"26#include "../__type_traits/is_volatile.h"27#include "../__type_traits/remove_cvref.h"28#include "../__utility/forward.h"29#include "../__utility/in_place.h"30#include "../__utility/move.h"31 32#include "../initializer_list"33 34#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)35#  pragma GCC system_header36#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)37#  pragma clang system_header38#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)39#  pragma system_header40#endif // no system header41 42_LIBCUDACXX_BEGIN_NAMESPACE_STD43 44#if _LIBCUDACXX_STD_VER > 1145 46template <class _Err>47class unexpected;48 49namespace __unexpected {50template <class _Tp>51_LIBCUDACXX_INLINE_VAR constexpr bool __is_unexpected = false;52 53template <class _Err>54_LIBCUDACXX_INLINE_VAR constexpr bool __is_unexpected<unexpected<_Err>> = true;55 56template <class _Tp>57_LIBCUDACXX_INLINE_VAR constexpr bool __valid_unexpected = _LIBCUDACXX_TRAIT(is_object, _Tp) &&58                                                          !_LIBCUDACXX_TRAIT(is_array, _Tp) &&59                                                          !__is_unexpected<_Tp> &&60                                                          !_LIBCUDACXX_TRAIT(is_const, _Tp) &&61                                                          !_LIBCUDACXX_TRAIT(is_volatile, _Tp);62} // namespace __unexpected63 64// [expected.un.general]65template <class _Err>66class unexpected {67  static_assert(__unexpected::__valid_unexpected<_Err>,68                "[expected.un.general] states a program that instantiates std::unexpected for a non-object type, an "69                "array type, a specialization of unexpected, or a cv-qualified type is ill-formed.");70 71  template <class, class>72  friend class expected;73 74public:75  // [expected.un.ctor]76  _LIBCUDACXX_HIDE_FROM_ABI unexpected(const unexpected&) = default;77  _LIBCUDACXX_HIDE_FROM_ABI unexpected(unexpected&&)      = default;78 79  _LIBCUDACXX_TEMPLATE(class _Error = _Err)80    _LIBCUDACXX_REQUIRES( (!_LIBCUDACXX_TRAIT(is_same, remove_cvref_t<_Error>, unexpected) &&81               !_LIBCUDACXX_TRAIT(is_same, remove_cvref_t<_Error>, in_place_t) &&82               _LIBCUDACXX_TRAIT(is_constructible, _Err, _Error)))83  _LIBCUDACXX_INLINE_VISIBILITY84  constexpr explicit unexpected(_Error&& __error) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Error))85    : __unex_(_CUDA_VSTD::forward<_Error>(__error)) {}86 87  _LIBCUDACXX_TEMPLATE(class... _Args)88    _LIBCUDACXX_REQUIRES( _LIBCUDACXX_TRAIT(is_constructible, _Err, _Args...))89  _LIBCUDACXX_INLINE_VISIBILITY90  constexpr explicit unexpected(in_place_t, _Args&&... __args) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, _Args...))91    : __unex_(_CUDA_VSTD::forward<_Args>(__args)...) {}92 93  _LIBCUDACXX_TEMPLATE(class _Up, class... _Args)94    _LIBCUDACXX_REQUIRES( _LIBCUDACXX_TRAIT(is_constructible, _Err, initializer_list<_Up>&, _Args...))95  _LIBCUDACXX_INLINE_VISIBILITY96  constexpr explicit unexpected(in_place_t, initializer_list<_Up> __il, _Args&&... __args) noexcept(97    _LIBCUDACXX_TRAIT(is_nothrow_constructible, _Err, initializer_list<_Up>&, _Args...))98    : __unex_(__il, _CUDA_VSTD::forward<_Args>(__args)...) {}99 100  constexpr unexpected& operator=(const unexpected&) = default;101  constexpr unexpected& operator=(unexpected&&)      = default;102 103  // [expected.un.obs]104  _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY105  constexpr const _Err& error() const& noexcept {106    return __unex_;107  }108 109  _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY110  constexpr _Err& error() & noexcept {111    return __unex_;112  }113 114  _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY115  constexpr const _Err&& error() const&& noexcept {116    return _CUDA_VSTD::move(__unex_);117  }118 119  _LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY120  constexpr _Err&& error() && noexcept {121    return _CUDA_VSTD::move(__unex_);122  }123 124  // [expected.un.swap]125  _LIBCUDACXX_INLINE_VISIBILITY126  constexpr void swap(unexpected& __other) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_swappable, _Err)) {127    static_assert(_LIBCUDACXX_TRAIT(is_swappable, _Err), "E must be swappable");128    using _CUDA_VSTD::swap;129    swap(__unex_, __other.__unex_);130  }131 132  _LIBCUDACXX_TEMPLATE(class _Err2 = _Err)133    _LIBCUDACXX_REQUIRES( _LIBCUDACXX_TRAIT(is_swappable, _Err2))134  friend _LIBCUDACXX_INLINE_VISIBILITY constexpr135  void swap(unexpected& __lhs, unexpected& __rhs) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_swappable, _Err2))136  {137    __lhs.swap(__rhs);138    return;139  }140 141  // [expected.un.eq]142  template <class _UErr>143  friend _LIBCUDACXX_INLINE_VISIBILITY constexpr144  _LIBCUDACXX_NODISCARD_EXT bool operator==(const unexpected& __lhs, const unexpected<_UErr>& __rhs) noexcept(145    noexcept(static_cast<bool>(__lhs.error() == __rhs.error()))) {146    return __lhs.error() == __rhs.error();147  }148#if _LIBCUDACXX_STD_VER < 20149  template <class _UErr>150  _LIBCUDACXX_INLINE_VISIBILITY151  _LIBCUDACXX_NODISCARD_EXT friend constexpr bool operator!=(const unexpected& __lhs, const unexpected<_UErr>& __rhs) noexcept(152    noexcept(static_cast<bool>(__lhs.error() != __rhs.error()))) {153    return __lhs.error() != __rhs.error();154  }155#endif156 157private:158  _Err __unex_;159};160 161#if _LIBCUDACXX_STD_VER > 14 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES)162template <class _Err>163unexpected(_Err) -> unexpected<_Err>;164#endif // _LIBCUDACXX_STD_VER > 14 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES)165 166#endif // _LIBCUDACXX_STD_VER > 11167 168_LIBCUDACXX_END_NAMESPACE_STD169 170#endif // _LIBCUDACXX___EXPECTED_UNEXPECTED_H171 
codekingpro/portable-devtools · Team Ai