From 7333e0b43767d14c9fe3ad86b9f1c3853bc393ad Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Wed, 24 Apr 2024 14:02:35 +0200 Subject: [PATCH] Format optional --- .../cuda/std/detail/libcxx/include/optional | 1617 ++++++++--------- 1 file changed, 779 insertions(+), 838 deletions(-) diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/optional b/libcudacxx/include/cuda/std/detail/libcxx/include/optional index a21d5592f70..32902756432 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/optional +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/optional @@ -169,8 +169,6 @@ template # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler -#include #include #include #include @@ -183,12 +181,12 @@ template #include #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -196,6 +194,8 @@ template #include #include #include +#include // all public C++ headers provide the assertion handler +#include #include #include #include @@ -206,7 +206,7 @@ template // [optional.syn] #ifndef _LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR -#include +# include #endif // !_LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR #include @@ -240,13 +240,17 @@ _CCCL_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY void __throw_bad_optional_ac struct nullopt_t { - struct __secret_tag { explicit __secret_tag() = default; }; - _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit nullopt_t(__secret_tag, __secret_tag) noexcept {} + struct __secret_tag + { + explicit __secret_tag() = default; + }; + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit nullopt_t(__secret_tag, __secret_tag) noexcept {} }; _LIBCUDACXX_CPO_ACCESSIBILITY nullopt_t nullopt{nullopt_t::__secret_tag{}, nullopt_t::__secret_tag{}}; -struct __optional_construct_from_invoke_tag {}; +struct __optional_construct_from_invoke_tag +{}; template ::value> struct __optional_destruct_base; @@ -254,338 +258,333 @@ struct __optional_destruct_base; template struct __optional_destruct_base<_Tp, false> { - typedef _Tp value_type; - static_assert(_LIBCUDACXX_TRAIT(is_object, value_type), - "instantiation of optional with a non-object type is undefined behavior"); - union - { - char __null_state_; - __remove_cv_t __val_; - }; - bool __engaged_; + typedef _Tp value_type; + static_assert(_LIBCUDACXX_TRAIT(is_object, value_type), + "instantiation of optional with a non-object type is undefined behavior"); + union + { + char __null_state_; + __remove_cv_t __val_; + }; + bool __engaged_; - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX20 ~__optional_destruct_base() + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX20 ~__optional_destruct_base() + { + if (__engaged_) { - if (__engaged_) - __val_.~value_type(); + __val_.~value_type(); } + } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_destruct_base() noexcept - : __null_state_(), - __engaged_(false) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) - : __val_(_CUDA_VSTD::forward<_Args>(__args)...), - __engaged_(true) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) - : __val_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_Args>(__args)...)), __engaged_(true) {} - - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX20 void reset() noexcept + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_destruct_base() noexcept + : __null_state_() + , __engaged_(false) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) + : __val_(_CUDA_VSTD::forward<_Args>(__args)...) + , __engaged_(true) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_destruct_base( + __optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) + : __val_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_Args>(__args)...)) + , __engaged_(true) + {} + + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX20 void reset() noexcept + { + if (__engaged_) { - if (__engaged_) - { - __val_.~value_type(); - __engaged_ = false; - } + __val_.~value_type(); + __engaged_ = false; } + } }; template struct __optional_destruct_base<_Tp, true> { - typedef _Tp value_type; - static_assert(_LIBCUDACXX_TRAIT(is_object, value_type), - "instantiation of optional with a non-object type is undefined behavior"); - union - { - char __null_state_; - __remove_cv_t __val_; - }; - bool __engaged_; - - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_destruct_base() noexcept - : __null_state_(), - __engaged_(false) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) - : __val_(_CUDA_VSTD::forward<_Args>(__args)...), - __engaged_(true) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) - : __val_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_Args>(__args)...)), __engaged_(true) {} - - _LIBCUDACXX_INLINE_VISIBILITY - constexpr void reset() noexcept + typedef _Tp value_type; + static_assert(_LIBCUDACXX_TRAIT(is_object, value_type), + "instantiation of optional with a non-object type is undefined behavior"); + union + { + char __null_state_; + __remove_cv_t __val_; + }; + bool __engaged_; + + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_destruct_base() noexcept + : __null_state_() + , __engaged_(false) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) + : __val_(_CUDA_VSTD::forward<_Args>(__args)...) + , __engaged_(true) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_destruct_base( + __optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) + : __val_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_Args>(__args)...)) + , __engaged_(true) + {} + + _LIBCUDACXX_INLINE_VISIBILITY constexpr void reset() noexcept + { + if (__engaged_) { - if (__engaged_) - { - __engaged_ = false; - } + __engaged_ = false; } + } }; template struct __optional_storage_base : __optional_destruct_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_storage_base, __optional_destruct_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_storage_base, __optional_destruct_base, _Tp); - using value_type = _Tp; + using value_type = _Tp; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr bool has_value() const noexcept - { - return this->__engaged_; - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr bool has_value() const noexcept + { + return this->__engaged_; + } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr value_type& __get() & noexcept - { - return this->__val_; - } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr const value_type& __get() const& noexcept - { - return this->__val_; - } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr value_type&& __get() && noexcept - { - return _CUDA_VSTD::move(this->__val_); - } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr const value_type&& __get() const&& noexcept - { - return _CUDA_VSTD::move(this->__val_); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr value_type& __get() & noexcept + { + return this->__val_; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr const value_type& __get() const& noexcept + { + return this->__val_; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr value_type&& __get() && noexcept + { + return _CUDA_VSTD::move(this->__val_); + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr const value_type&& __get() const&& noexcept + { + return _CUDA_VSTD::move(this->__val_); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX20 void __construct(_Args&&... __args) + { + _LIBCUDACXX_ASSERT(!has_value(), "__construct called for engaged __optional_storage"); +# if _CCCL_STD_VER > 2017 + _CUDA_VSTD::construct_at(_CUDA_VSTD::addressof(this->__val_), _CUDA_VSTD::forward<_Args>(__args)...); +# else + ::new ((void*) _CUDA_VSTD::addressof(this->__val_)) value_type(_CUDA_VSTD::forward<_Args>(__args)...); +# endif + this->__engaged_ = true; + } - template - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX20 void __construct(_Args&&... __args) + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr void __construct_from(_That&& __opt) + { + if (__opt.has_value()) { - _LIBCUDACXX_ASSERT(!has_value(), "__construct called for engaged __optional_storage"); -#if _CCCL_STD_VER > 2017 - _CUDA_VSTD::construct_at(_CUDA_VSTD::addressof(this->__val_), _CUDA_VSTD::forward<_Args>(__args)...); -#else - ::new ((void*)_CUDA_VSTD::addressof(this->__val_)) value_type(_CUDA_VSTD::forward<_Args>(__args)...); -#endif - this->__engaged_ = true; + __construct(_CUDA_VSTD::forward<_That>(__opt).__get()); } + } - template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr void __construct_from(_That&& __opt) + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr void __assign_from(_That&& __opt) + { + if (this->__engaged_ == __opt.has_value()) { - if (__opt.has_value()) - __construct(_CUDA_VSTD::forward<_That>(__opt).__get()); + if (this->__engaged_) + { + this->__val_ = _CUDA_VSTD::forward<_That>(__opt).__get(); + } } - - template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr void __assign_from(_That&& __opt) + else { - if (this->__engaged_ == __opt.has_value()) - { - if (this->__engaged_) - this->__val_ = _CUDA_VSTD::forward<_That>(__opt).__get(); - } - else - { - if (this->__engaged_) - this->reset(); - else - __construct(_CUDA_VSTD::forward<_That>(__opt).__get()); - } + if (this->__engaged_) + { + this->reset(); + } + else + { + __construct(_CUDA_VSTD::forward<_That>(__opt).__get()); + } } + } }; template ::value> struct __optional_copy_base : __optional_storage_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_base, __optional_storage_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_base, __optional_storage_base, _Tp); }; template struct __optional_copy_base<_Tp, false> : __optional_storage_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_base, __optional_storage_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_base, __optional_storage_base, _Tp); - // This ctor shouldn't need to initialize the base explicitly, but g++ 9 considers it to be uninitialized - // during constexpr evaluation if it isn't initialized explicitly. This can be replaced with the pattern - // below, in __optional_move_base, once g++ 9 falls off our support matrix. - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_copy_base(const __optional_copy_base& __opt) : __base() - { - this->__construct_from(__opt); - } + // This ctor shouldn't need to initialize the base explicitly, but g++ 9 considers it to be uninitialized + // during constexpr evaluation if it isn't initialized explicitly. This can be replaced with the pattern + // below, in __optional_move_base, once g++ 9 falls off our support matrix. + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_copy_base(const __optional_copy_base& __opt) + : __base() + { + this->__construct_from(__opt); + } - __optional_copy_base(__optional_copy_base&&) = default; - __optional_copy_base& operator=(const __optional_copy_base&) = default; - __optional_copy_base& operator=(__optional_copy_base&&) = default; + __optional_copy_base(__optional_copy_base&&) = default; + __optional_copy_base& operator=(const __optional_copy_base&) = default; + __optional_copy_base& operator=(__optional_copy_base&&) = default; }; template ::value> struct __optional_move_base : __optional_copy_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_base, __optional_copy_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_base, __optional_copy_base, _Tp); }; template struct __optional_move_base<_Tp, false> : __optional_copy_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_base, __optional_copy_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_base, __optional_copy_base, _Tp); - __optional_move_base(const __optional_move_base&) = default; + __optional_move_base(const __optional_move_base&) = default; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_move_base(__optional_move_base&& __opt) - noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp)) - { - this->__construct_from(_CUDA_VSTD::move(__opt)); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_move_base(__optional_move_base&& __opt) noexcept( + _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp)) + { + this->__construct_from(_CUDA_VSTD::move(__opt)); + } - __optional_move_base& operator=(const __optional_move_base&) = default; - __optional_move_base& operator=(__optional_move_base&&) = default; + __optional_move_base& operator=(const __optional_move_base&) = default; + __optional_move_base& operator=(__optional_move_base&&) = default; }; -template ::value && - is_trivially_copy_constructible<_Tp>::value && - is_trivially_copy_assignable<_Tp>::value> +template ::value && is_trivially_copy_constructible<_Tp>::value + && is_trivially_copy_assignable<_Tp>::value> struct __optional_copy_assign_base : __optional_move_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_assign_base, __optional_move_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_assign_base, __optional_move_base, _Tp); }; template struct __optional_copy_assign_base<_Tp, false> : __optional_move_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_assign_base, __optional_move_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_assign_base, __optional_move_base, _Tp); - __optional_copy_assign_base(const __optional_copy_assign_base&) = default; - __optional_copy_assign_base(__optional_copy_assign_base&&) = default; + __optional_copy_assign_base(const __optional_copy_assign_base&) = default; + __optional_copy_assign_base(__optional_copy_assign_base&&) = default; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_copy_assign_base& operator=(const __optional_copy_assign_base& __opt) - { - this->__assign_from(__opt); - return *this; - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_copy_assign_base& + operator=(const __optional_copy_assign_base& __opt) + { + this->__assign_from(__opt); + return *this; + } - __optional_copy_assign_base& operator=(__optional_copy_assign_base&&) = default; + __optional_copy_assign_base& operator=(__optional_copy_assign_base&&) = default; }; -template ::value && - is_trivially_move_constructible<_Tp>::value && - is_trivially_move_assignable<_Tp>::value> +template ::value && is_trivially_move_constructible<_Tp>::value + && is_trivially_move_assignable<_Tp>::value> struct __optional_move_assign_base : __optional_copy_assign_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_assign_base, __optional_copy_assign_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_assign_base, __optional_copy_assign_base, _Tp); }; template struct __optional_move_assign_base<_Tp, false> : __optional_copy_assign_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_assign_base, __optional_copy_assign_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_assign_base, __optional_copy_assign_base, _Tp); - __optional_move_assign_base(const __optional_move_assign_base& __opt) = default; - __optional_move_assign_base(__optional_move_assign_base&&) = default; - __optional_move_assign_base& operator=(const __optional_move_assign_base&) = default; + __optional_move_assign_base(const __optional_move_assign_base& __opt) = default; + __optional_move_assign_base(__optional_move_assign_base&&) = default; + __optional_move_assign_base& operator=(const __optional_move_assign_base&) = default; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_move_assign_base& operator=(__optional_move_assign_base&& __opt) - noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_assignable, _Tp) && - _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp)) - { - this->__assign_from(_CUDA_VSTD::move(__opt)); - return *this; - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_move_assign_base& + operator=(__optional_move_assign_base&& __opt) noexcept( + _LIBCUDACXX_TRAIT(is_nothrow_move_assignable, _Tp) && _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp)) + { + this->__assign_from(_CUDA_VSTD::move(__opt)); + return *this; + } }; template -using __optional_sfinae_ctor_base_t = __sfinae_ctor_base< - is_copy_constructible<_Tp>::value, - is_move_constructible<_Tp>::value ->; +using __optional_sfinae_ctor_base_t = + __sfinae_ctor_base::value, is_move_constructible<_Tp>::value>; template -using __optional_sfinae_assign_base_t = __sfinae_assign_base< - (is_copy_constructible<_Tp>::value && is_copy_assignable<_Tp>::value), - (is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value) ->; +using __optional_sfinae_assign_base_t = + __sfinae_assign_base<(is_copy_constructible<_Tp>::value && is_copy_assignable<_Tp>::value), + (is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value)>; -template +template class optional; template -struct __is_std_optional : false_type {}; -template +struct __is_std_optional : false_type +{}; +template struct __is_std_optional> : true_type -{ -}; +{}; // Constraits template > -using __opt_check_constructible_from_opt = _Or< - is_constructible<_Tp, _Opt&>, - is_constructible<_Tp, _Opt const&>, - is_constructible<_Tp, _Opt&&>, - is_constructible<_Tp, _Opt const&&>, - is_convertible<_Opt&, _Tp>, - is_convertible<_Opt const&, _Tp>, - is_convertible<_Opt&&, _Tp>, - is_convertible<_Opt const&&, _Tp> ->; +using __opt_check_constructible_from_opt = + _Or, + is_constructible<_Tp, _Opt const&>, + is_constructible<_Tp, _Opt&&>, + is_constructible<_Tp, _Opt const&&>, + is_convertible<_Opt&, _Tp>, + is_convertible<_Opt const&, _Tp>, + is_convertible<_Opt&&, _Tp>, + is_convertible<_Opt const&&, _Tp>>; template > -using __opt_check_assignable_from_opt = _Or< - is_assignable<_Tp&, _Opt&>, - is_assignable<_Tp&, _Opt const&>, - is_assignable<_Tp&, _Opt&&>, - is_assignable<_Tp&, _Opt const&&> ->; - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_implictly_constructible = _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) - && _LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp); - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_explictly_constructible = _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) - && !_LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp); - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_constructible_from_U = !_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, in_place_t) - && !_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, optional<_Tp>); - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_constructible_from_opt = !_LIBCUDACXX_TRAIT(is_same, _Up, _Tp) - && !__opt_check_constructible_from_opt<_Tp, _Up>::value; - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_assignable = _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) - && _LIBCUDACXX_TRAIT(is_assignable, _Tp&, _Up); - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_assignable_from_U = !_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, optional<_Tp>) - && (!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, _Tp) - || !_LIBCUDACXX_TRAIT(is_scalar, _Tp)); - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_assignable_from_opt = !_LIBCUDACXX_TRAIT(is_same, _Up, _Tp) - && !__opt_check_constructible_from_opt<_Tp, _Up>::value - && !__opt_check_assignable_from_opt<_Tp, _Up>::value; +using __opt_check_assignable_from_opt = + _Or, + is_assignable<_Tp&, _Opt const&>, + is_assignable<_Tp&, _Opt&&>, + is_assignable<_Tp&, _Opt const&&>>; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_implictly_constructible = + _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) && _LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp); + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_explictly_constructible = + _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) && !_LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp); + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_constructible_from_U = + !_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, in_place_t) + && !_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, optional<_Tp>); + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_constructible_from_opt = + !_LIBCUDACXX_TRAIT(is_same, _Up, _Tp) && !__opt_check_constructible_from_opt<_Tp, _Up>::value; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_assignable = + _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) && _LIBCUDACXX_TRAIT(is_assignable, _Tp&, _Up); + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_assignable_from_U = + !_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, optional<_Tp>) + && (!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, _Tp) || !_LIBCUDACXX_TRAIT(is_scalar, _Tp)); + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_assignable_from_opt = + !_LIBCUDACXX_TRAIT(is_same, _Up, _Tp) && !__opt_check_constructible_from_opt<_Tp, _Up>::value + && !__opt_check_assignable_from_opt<_Tp, _Up>::value; template class optional @@ -593,830 +592,772 @@ class optional , private __optional_sfinae_ctor_base_t<_Tp> , private __optional_sfinae_assign_base_t<_Tp> { - using __base = __optional_move_assign_base<_Tp>; + using __base = __optional_move_assign_base<_Tp>; - template - friend class optional; + template + friend class optional; public: - using value_type = _Tp; + using value_type = _Tp; private: - // Disable the reference extension using this static assert. - static_assert(!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t, in_place_t), - "instantiation of optional with in_place_t is ill-formed"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t, nullopt_t), - "instantiation of optional with nullopt_t is ill-formed"); - static_assert(!_LIBCUDACXX_TRAIT(is_reference, value_type), - "instantiation of optional with a reference type is ill-formed"); - static_assert(_LIBCUDACXX_TRAIT(is_destructible, value_type), - "instantiation of optional with a non-destructible type is ill-formed"); - static_assert(!_LIBCUDACXX_TRAIT(is_array, value_type), - "instantiation of optional with an array type is ill-formed"); + // Disable the reference extension using this static assert. + static_assert(!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t, in_place_t), + "instantiation of optional with in_place_t is ill-formed"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t, nullopt_t), + "instantiation of optional with nullopt_t is ill-formed"); + static_assert(!_LIBCUDACXX_TRAIT(is_reference, value_type), + "instantiation of optional with a reference type is ill-formed"); + static_assert(_LIBCUDACXX_TRAIT(is_destructible, value_type), + "instantiation of optional with a non-destructible type is ill-formed"); + static_assert(!_LIBCUDACXX_TRAIT(is_array, value_type), "instantiation of optional with an array type is ill-formed"); public: + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional() noexcept {} + constexpr optional(const optional&) = default; + constexpr optional(optional&&) = default; + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional(nullopt_t) noexcept {} + + _LIBCUDACXX_TEMPLATE(class _In_place_t, class... _Args) + _LIBCUDACXX_REQUIRES(_LIBCUDACXX_TRAIT(is_same, _In_place_t, in_place_t) + _LIBCUDACXX_AND _LIBCUDACXX_TRAIT(is_constructible, value_type, _Args...)) + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit optional(_In_place_t, _Args&&... __args) + : __base(in_place, _CUDA_VSTD::forward<_Args>(__args)...) + {} + + _LIBCUDACXX_TEMPLATE(class _Up, class... _Args) + _LIBCUDACXX_REQUIRES(_LIBCUDACXX_TRAIT(is_constructible, value_type, initializer_list<_Up>&, _Args...)) + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args) + : __base(in_place, __il, _CUDA_VSTD::forward<_Args>(__args)...) + {} + + _LIBCUDACXX_TEMPLATE(class _Up = value_type) + _LIBCUDACXX_REQUIRES( + __opt_is_constructible_from_U<_Tp, _Up> _LIBCUDACXX_AND __opt_is_implictly_constructible<_Tp, _Up>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional(_Up&& __v) + : __base(in_place, _CUDA_VSTD::forward<_Up>(__v)) + {} + + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES( + __opt_is_constructible_from_U<_Tp, _Up> _LIBCUDACXX_AND __opt_is_explictly_constructible<_Tp, _Up>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit optional(_Up&& __v) + : __base(in_place, _CUDA_VSTD::forward<_Up>(__v)) + {} + + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES( + __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND __opt_is_implictly_constructible<_Tp, const _Up&>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional(const optional<_Up>& __v) + { + this->__construct_from(__v); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr optional() noexcept {} - constexpr optional(const optional&) = default; - constexpr optional(optional&&) = default; - _LIBCUDACXX_INLINE_VISIBILITY constexpr optional(nullopt_t) noexcept {} - - _LIBCUDACXX_TEMPLATE(class _In_place_t, class... _Args) - _LIBCUDACXX_REQUIRES( _LIBCUDACXX_TRAIT(is_same, _In_place_t, in_place_t) _LIBCUDACXX_AND - _LIBCUDACXX_TRAIT(is_constructible, value_type, _Args...)) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit optional(_In_place_t, _Args&&... __args) - : __base(in_place, _CUDA_VSTD::forward<_Args>(__args)...) {} - - _LIBCUDACXX_TEMPLATE(class _Up, class... _Args) - _LIBCUDACXX_REQUIRES( _LIBCUDACXX_TRAIT(is_constructible, value_type, initializer_list<_Up>&, _Args...)) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args) - : __base(in_place, __il, _CUDA_VSTD::forward<_Args>(__args)...) {} - - _LIBCUDACXX_TEMPLATE(class _Up = value_type) - _LIBCUDACXX_REQUIRES( __opt_is_constructible_from_U<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_implictly_constructible<_Tp, _Up>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional(_Up&& __v) : __base(in_place, _CUDA_VSTD::forward<_Up>(__v)) {} - - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_constructible_from_U<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_explictly_constructible<_Tp, _Up>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit optional(_Up&& __v) : __base(in_place, _CUDA_VSTD::forward<_Up>(__v)) {} - - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_implictly_constructible<_Tp, const _Up&>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional(const optional<_Up>& __v) { - this->__construct_from(__v); - } - - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_explictly_constructible<_Tp, const _Up&>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit optional(const optional<_Up>& __v) { - this->__construct_from(__v); - } + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES( + __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND __opt_is_explictly_constructible<_Tp, const _Up&>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit optional(const optional<_Up>& __v) + { + this->__construct_from(__v); + } - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_implictly_constructible<_Tp, _Up>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional(optional<_Up>&& __v) { - this->__construct_from(_CUDA_VSTD::move(__v)); - } + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES( + __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND __opt_is_implictly_constructible<_Tp, _Up>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional(optional<_Up>&& __v) + { + this->__construct_from(_CUDA_VSTD::move(__v)); + } - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_explictly_constructible<_Tp, _Up>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit optional(optional<_Up>&& __v) { - this->__construct_from(_CUDA_VSTD::move(__v)); - } + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES( + __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND __opt_is_explictly_constructible<_Tp, _Up>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit optional(optional<_Up>&& __v) + { + this->__construct_from(_CUDA_VSTD::move(__v)); + } private: - template - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit optional(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) - : __base(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_Args>(__args)...) { - } + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit optional( + __optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) + : __base( + __optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_Args>(__args)...) + {} public: + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional& operator=(nullopt_t) noexcept + { + reset(); + return *this; + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional& operator=(nullopt_t) noexcept { - reset(); - return *this; - } + constexpr optional& operator=(const optional&) = default; + constexpr optional& operator=(optional&&) = default; - constexpr optional& operator=(const optional&) = default; - constexpr optional& operator=(optional&&) = default; - - _LIBCUDACXX_TEMPLATE(class _Up = value_type) - _LIBCUDACXX_REQUIRES( __opt_is_assignable_from_U<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_assignable<_Tp, _Up>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional& operator=(_Up&& __v) { - if (this->has_value()) - this->__get() = _CUDA_VSTD::forward<_Up>(__v); - else - this->__construct(_CUDA_VSTD::forward<_Up>(__v)); - return *this; + _LIBCUDACXX_TEMPLATE(class _Up = value_type) + _LIBCUDACXX_REQUIRES(__opt_is_assignable_from_U<_Tp, _Up> _LIBCUDACXX_AND __opt_is_assignable<_Tp, _Up>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional& operator=(_Up&& __v) + { + if (this->has_value()) + { + this->__get() = _CUDA_VSTD::forward<_Up>(__v); } - - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_assignable_from_opt<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_assignable<_Tp, const _Up&>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional& operator=(const optional<_Up>& __v) { - this->__assign_from(__v); - return *this; + else + { + this->__construct(_CUDA_VSTD::forward<_Up>(__v)); } + return *this; + } - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_assignable_from_opt<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_assignable<_Tp, _Up>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional& operator=(optional<_Up>&& __v) { - this->__assign_from(_CUDA_VSTD::move(__v)); - return *this; - } + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES(__opt_is_assignable_from_opt<_Tp, _Up> _LIBCUDACXX_AND __opt_is_assignable<_Tp, const _Up&>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional& operator=(const optional<_Up>& __v) + { + this->__assign_from(__v); + return *this; + } - template = 0> - _LIBCUDACXX_INLINE_VISIBILITY constexpr - _Tp& emplace(_Args&&... __args) { - reset(); - this->__construct(_CUDA_VSTD::forward<_Args>(__args)...); - return this->__get(); - } + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES(__opt_is_assignable_from_opt<_Tp, _Up> _LIBCUDACXX_AND __opt_is_assignable<_Tp, _Up>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional& operator=(optional<_Up>&& __v) + { + this->__assign_from(_CUDA_VSTD::move(__v)); + return *this; + } - template&, _Args...), int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY constexpr - _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) { - reset(); - this->__construct(__il, _CUDA_VSTD::forward<_Args>(__args)...); - return this->__get(); - } + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr _Tp& emplace(_Args&&... __args) + { + reset(); + this->__construct(_CUDA_VSTD::forward<_Args>(__args)...); + return this->__get(); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - void swap(optional& __opt) - noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, value_type) && - _LIBCUDACXX_TRAIT(is_nothrow_swappable, value_type)) - { - if (this->has_value() == __opt.has_value()) - { - using _CUDA_VSTD::swap; - if (this->has_value()) - swap(this->__get(), __opt.__get()); - } - else - { - if (this->has_value()) - { - __opt.__construct(_CUDA_VSTD::move(this->__get())); - reset(); - } - else - { - this->__construct(_CUDA_VSTD::move(__opt.__get())); - __opt.reset(); - } - } - } + template &, _Args...), int> = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) + { + reset(); + this->__construct(__il, _CUDA_VSTD::forward<_Args>(__args)...); + return this->__get(); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - add_pointer_t operator->() const + _LIBCUDACXX_INLINE_VISIBILITY constexpr void swap(optional& __opt) noexcept( + _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, value_type) && _LIBCUDACXX_TRAIT(is_nothrow_swappable, value_type)) + { + if (this->has_value() == __opt.has_value()) { - _LIBCUDACXX_ASSERT(this->has_value(), "optional operator-> called on a disengaged value"); - return _CUDA_VSTD::addressof(this->__get()); + using _CUDA_VSTD::swap; + if (this->has_value()) + { + swap(this->__get(), __opt.__get()); + } } - - _LIBCUDACXX_INLINE_VISIBILITY constexpr - add_pointer_t operator->() + else { - _LIBCUDACXX_ASSERT(this->has_value(), "optional operator-> called on a disengaged value"); - return _CUDA_VSTD::addressof(this->__get()); + if (this->has_value()) + { + __opt.__construct(_CUDA_VSTD::move(this->__get())); + reset(); + } + else + { + this->__construct(_CUDA_VSTD::move(__opt.__get())); + __opt.reset(); + } } + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - const value_type& operator*() const& noexcept - { - _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); - return this->__get(); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr add_pointer_t operator->() const + { + _LIBCUDACXX_ASSERT(this->has_value(), "optional operator-> called on a disengaged value"); + return _CUDA_VSTD::addressof(this->__get()); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - value_type& operator*() & noexcept - { - _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); - return this->__get(); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr add_pointer_t operator->() + { + _LIBCUDACXX_ASSERT(this->has_value(), "optional operator-> called on a disengaged value"); + return _CUDA_VSTD::addressof(this->__get()); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - value_type&& operator*() && noexcept - { - _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); - return _CUDA_VSTD::move(this->__get()); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr const value_type& operator*() const& noexcept + { + _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); + return this->__get(); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - const value_type&& operator*() const&& noexcept - { - _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); - return _CUDA_VSTD::move(this->__get()); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr value_type& operator*() & noexcept + { + _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); + return this->__get(); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit operator bool() const noexcept { return has_value(); } + _LIBCUDACXX_INLINE_VISIBILITY constexpr value_type&& operator*() && noexcept + { + _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); + return _CUDA_VSTD::move(this->__get()); + } - using __base::has_value; - using __base::__get; + _LIBCUDACXX_INLINE_VISIBILITY constexpr const value_type&& operator*() const&& noexcept + { + _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); + return _CUDA_VSTD::move(this->__get()); + } - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - value_type const& value() const& - { - if (!this->has_value()) - __throw_bad_optional_access(); - return this->__get(); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit operator bool() const noexcept + { + return has_value(); + } + + using __base::__get; + using __base::has_value; - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - value_type& value() & + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr value_type const& + value() const& + { + if (!this->has_value()) { - if (!this->has_value()) - __throw_bad_optional_access(); - return this->__get(); + __throw_bad_optional_access(); } + return this->__get(); + } - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - value_type&& value() && + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr value_type& value() & + { + if (!this->has_value()) { - if (!this->has_value()) - __throw_bad_optional_access(); - return _CUDA_VSTD::move(this->__get()); + __throw_bad_optional_access(); } + return this->__get(); + } - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - value_type const&& value() const&& + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr value_type&& value() && + { + if (!this->has_value()) { - if (!this->has_value()) - __throw_bad_optional_access(); - return _CUDA_VSTD::move(this->__get()); + __throw_bad_optional_access(); } + return _CUDA_VSTD::move(this->__get()); + } - template - _LIBCUDACXX_INLINE_VISIBILITY constexpr - value_type value_or(_Up&& __v) const& + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr value_type const&& + value() const&& + { + if (!this->has_value()) { - static_assert(_LIBCUDACXX_TRAIT(is_copy_constructible, value_type), - "optional::value_or: T must be copy constructible"); - static_assert(_LIBCUDACXX_TRAIT(is_convertible, _Up, value_type), - "optional::value_or: U must be convertible to T"); - return this->has_value() ? this->__get() : - static_cast(_CUDA_VSTD::forward<_Up>(__v)); + __throw_bad_optional_access(); } + return _CUDA_VSTD::move(this->__get()); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr value_type value_or(_Up&& __v) const& + { + static_assert(_LIBCUDACXX_TRAIT(is_copy_constructible, value_type), + "optional::value_or: T must be copy constructible"); + static_assert(_LIBCUDACXX_TRAIT(is_convertible, _Up, value_type), + "optional::value_or: U must be convertible to T"); + return this->has_value() ? this->__get() : static_cast(_CUDA_VSTD::forward<_Up>(__v)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr value_type value_or(_Up&& __v) && + { + static_assert(_LIBCUDACXX_TRAIT(is_move_constructible, value_type), + "optional::value_or: T must be move constructible"); + static_assert(_LIBCUDACXX_TRAIT(is_convertible, _Up, value_type), + "optional::value_or: U must be convertible to T"); + return this->has_value() ? _CUDA_VSTD::move(this->__get()) : static_cast(_CUDA_VSTD::forward<_Up>(__v)); + } - template - _LIBCUDACXX_INLINE_VISIBILITY constexpr - value_type value_or(_Up&& __v) && + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto and_then(_Func&& __f) & + { + using _Up = invoke_result_t<_Func, value_type&>; + static_assert(__is_std_optional>::value, + "Result of f(value()) must be a specialization of std::optional"); + if (this->__engaged_) { - static_assert(_LIBCUDACXX_TRAIT(is_move_constructible, value_type), - "optional::value_or: T must be move constructible"); - static_assert(_LIBCUDACXX_TRAIT(is_convertible, _Up, value_type), - "optional::value_or: U must be convertible to T"); - return this->has_value() ? _CUDA_VSTD::move(this->__get()) : - static_cast(_CUDA_VSTD::forward<_Up>(__v)); + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), this->__get()); } + return remove_cvref_t<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto and_then(_Func&& __f) & { - using _Up = invoke_result_t<_Func, value_type&>; - static_assert(__is_std_optional>::value, - "Result of f(value()) must be a specialization of std::optional"); - if (this->__engaged_) - { - return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), this->__get()); - } - return remove_cvref_t<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + and_then(_Func&& __f) const& + { + using _Up = invoke_result_t<_Func, const value_type&>; + static_assert(__is_std_optional>::value, + "Result of f(value()) must be a specialization of std::optional"); + if (this->__engaged_) + { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), this->__get()); } + return remove_cvref_t<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto and_then(_Func&& __f) const& { - using _Up = invoke_result_t<_Func, const value_type&>; - static_assert(__is_std_optional>::value, - "Result of f(value()) must be a specialization of std::optional"); - if (this->__engaged_) - { - return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), this->__get()); - } - return remove_cvref_t<_Up>(); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto and_then(_Func&& __f) && { - using _Up = invoke_result_t<_Func, value_type&&>; - static_assert(__is_std_optional>::value, - "Result of f(std::move(value())) must be a specialization of std::optional"); - if (this->__engaged_) - { - return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); - } - return remove_cvref_t<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + and_then(_Func&& __f) && + { + using _Up = invoke_result_t<_Func, value_type&&>; + static_assert(__is_std_optional>::value, + "Result of f(std::move(value())) must be a specialization of std::optional"); + if (this->__engaged_) + { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); } + return remove_cvref_t<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto and_then(_Func&& __f) const&& { - using _Up = invoke_result_t<_Func, const value_type&&>; - static_assert(__is_std_optional>::value, - "Result of f(std::move(value())) must be a specialization of std::optional"); - if (this->__engaged_) - { - return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); - } - return remove_cvref_t<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + and_then(_Func&& __f) const&& + { + using _Up = invoke_result_t<_Func, const value_type&&>; + static_assert(__is_std_optional>::value, + "Result of f(std::move(value())) must be a specialization of std::optional"); + if (this->__engaged_) + { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); } + return remove_cvref_t<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto transform(_Func&& __f) & { - using _Up = remove_cv_t>; - static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(value()) should not be an Array"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), - "Result of f(value()) should not be std::in_place_t"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), - "Result of f(value()) should not be std::nullopt_t"); - static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(value()) should be an object type"); - if (this->__engaged_) - { - return optional<_Up>(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), this->__get()); - } - return optional<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + transform(_Func&& __f) & + { + using _Up = remove_cv_t>; + static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(value()) should not be an Array"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), "Result of f(value()) should not be std::in_place_t"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), "Result of f(value()) should not be std::nullopt_t"); + static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(value()) should be an object type"); + if (this->__engaged_) + { + return optional<_Up>(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), this->__get()); } + return optional<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto transform(_Func&& __f) const& { - using _Up = remove_cv_t>; - static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(value()) should not be an Array"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), - "Result of f(value()) should not be std::in_place_t"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), - "Result of f(value()) should not be std::nullopt_t"); - static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(value()) should be an object type"); - if (this->__engaged_) - { - return optional<_Up>(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), this->__get()); - } - return optional<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + transform(_Func&& __f) const& + { + using _Up = remove_cv_t>; + static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(value()) should not be an Array"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), "Result of f(value()) should not be std::in_place_t"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), "Result of f(value()) should not be std::nullopt_t"); + static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(value()) should be an object type"); + if (this->__engaged_) + { + return optional<_Up>(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), this->__get()); } + return optional<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto transform(_Func&& __f) && { - using _Up = remove_cv_t>; - static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(std::move(value())) should not be an Array"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), - "Result of f(std::move(value())) should not be std::in_place_t"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), - "Result of f(std::move(value())) should not be std::nullopt_t"); - static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(std::move(value())) should be an object type"); - if (this->__engaged_) - { - return optional<_Up>(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); - } - return optional<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + transform(_Func&& __f) && + { + using _Up = remove_cv_t>; + static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(std::move(value())) should not be an Array"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), + "Result of f(std::move(value())) should not be std::in_place_t"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), + "Result of f(std::move(value())) should not be std::nullopt_t"); + static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(std::move(value())) should be an object type"); + if (this->__engaged_) + { + return optional<_Up>( + __optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); } + return optional<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto transform(_Func&& __f) const&& { - using _Up = remove_cvref_t>; - static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(std::move(value())) should not be an Array"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), - "Result of f(std::move(value())) should not be std::in_place_t"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), - "Result of f(std::move(value())) should not be std::nullopt_t"); - static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(std::move(value())) should be an object type"); - if (this->__engaged_) - { - return optional<_Up>(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); - } - return optional<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + transform(_Func&& __f) const&& + { + using _Up = remove_cvref_t>; + static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(std::move(value())) should not be an Array"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), + "Result of f(std::move(value())) should not be std::in_place_t"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), + "Result of f(std::move(value())) should not be std::nullopt_t"); + static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(std::move(value())) should be an object type"); + if (this->__engaged_) + { + return optional<_Up>( + __optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); } + return optional<_Up>(); + } - _LIBCUDACXX_TEMPLATE(class _Func, class _Tp2 = _Tp) - _LIBCUDACXX_REQUIRES( invocable<_Func> _LIBCUDACXX_AND _LIBCUDACXX_TRAIT(is_copy_constructible, _Tp2)) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional or_else(_Func&& __f) const& { - static_assert(_LIBCUDACXX_TRAIT(is_same, remove_cvref_t>, optional), - "Result of f() should be the same type as this optional"); - if (this->__engaged_) - { - return *this; - } - return _CUDA_VSTD::forward<_Func>(__f)(); + _LIBCUDACXX_TEMPLATE(class _Func, class _Tp2 = _Tp) + _LIBCUDACXX_REQUIRES(invocable<_Func> _LIBCUDACXX_AND _LIBCUDACXX_TRAIT(is_copy_constructible, _Tp2)) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional or_else(_Func&& __f) const& + { + static_assert(_LIBCUDACXX_TRAIT(is_same, remove_cvref_t>, optional), + "Result of f() should be the same type as this optional"); + if (this->__engaged_) + { + return *this; } + return _CUDA_VSTD::forward<_Func>(__f)(); + } - _LIBCUDACXX_TEMPLATE(class _Func, class _Tp2 = _Tp) - _LIBCUDACXX_REQUIRES( invocable<_Func> _LIBCUDACXX_AND _LIBCUDACXX_TRAIT(is_move_constructible, _Tp2)) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional or_else(_Func&& __f) && { - static_assert(_LIBCUDACXX_TRAIT(is_same, remove_cvref_t>, optional), - "Result of f() should be the same type as this optional"); - if (this->__engaged_) - { - return _CUDA_VSTD::move(*this); - } - return _CUDA_VSTD::forward<_Func>(__f)(); + _LIBCUDACXX_TEMPLATE(class _Func, class _Tp2 = _Tp) + _LIBCUDACXX_REQUIRES(invocable<_Func> _LIBCUDACXX_AND _LIBCUDACXX_TRAIT(is_move_constructible, _Tp2)) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional or_else(_Func&& __f) && + { + static_assert(_LIBCUDACXX_TRAIT(is_same, remove_cvref_t>, optional), + "Result of f() should be the same type as this optional"); + if (this->__engaged_) + { + return _CUDA_VSTD::move(*this); } + return _CUDA_VSTD::forward<_Func>(__f)(); + } - using __base::reset; + using __base::reset; }; -#if _CCCL_STD_VER > 2014 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES) -template +# if _CCCL_STD_VER > 2014 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES) +template _CCCL_HOST_DEVICE optional(_Tp) -> optional<_Tp>; -#endif +# endif // Comparisons between optionals template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() == declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() == declval()), bool), + bool> operator==(const optional<_Tp>& __x, const optional<_Up>& __y) { - if (static_cast(__x) != static_cast(__y)) - return false; - if (!static_cast(__x)) - return true; - return *__x == *__y; + if (static_cast(__x) != static_cast(__y)) + { + return false; + } + if (!static_cast(__x)) + { + return true; + } + return *__x == *__y; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() != - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() != declval()), bool), + bool> operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) { - if (static_cast(__x) != static_cast(__y)) - return true; - if (!static_cast(__x)) - return false; - return *__x != *__y; + if (static_cast(__x) != static_cast(__y)) + { + return true; + } + if (!static_cast(__x)) + { + return false; + } + return *__x != *__y; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() < - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() < declval()), bool), + bool> operator<(const optional<_Tp>& __x, const optional<_Up>& __y) { - if (!static_cast(__y)) - return false; - if (!static_cast(__x)) - return true; - return *__x < *__y; + if (!static_cast(__y)) + { + return false; + } + if (!static_cast(__x)) + { + return true; + } + return *__x < *__y; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() > - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() > declval()), bool), + bool> operator>(const optional<_Tp>& __x, const optional<_Up>& __y) { - if (!static_cast(__x)) - return false; - if (!static_cast(__y)) - return true; - return *__x > *__y; + if (!static_cast(__x)) + { + return false; + } + if (!static_cast(__y)) + { + return true; + } + return *__x > *__y; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() <= - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() <= declval()), bool), + bool> operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) { - if (!static_cast(__x)) - return true; - if (!static_cast(__y)) - return false; - return *__x <= *__y; + if (!static_cast(__x)) + { + return true; + } + if (!static_cast(__y)) + { + return false; + } + return *__x <= *__y; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() >= - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() >= declval()), bool), + bool> operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) { - if (!static_cast(__y)) - return true; - if (!static_cast(__x)) - return false; - return *__x >= *__y; + if (!static_cast(__y)) + { + return true; + } + if (!static_cast(__x)) + { + return false; + } + return *__x >= *__y; } // Comparisons with nullopt template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator==(const optional<_Tp>& __x, nullopt_t) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator==(const optional<_Tp>& __x, nullopt_t) noexcept { - return !static_cast(__x); + return !static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator==(nullopt_t, const optional<_Tp>& __x) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator==(nullopt_t, const optional<_Tp>& __x) noexcept { - return !static_cast(__x); + return !static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator!=(const optional<_Tp>& __x, nullopt_t) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator!=(const optional<_Tp>& __x, nullopt_t) noexcept { - return static_cast(__x); + return static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator!=(nullopt_t, const optional<_Tp>& __x) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator!=(nullopt_t, const optional<_Tp>& __x) noexcept { - return static_cast(__x); + return static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator<(const optional<_Tp>&, nullopt_t) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator<(const optional<_Tp>&, nullopt_t) noexcept { - return false; + return false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator<(nullopt_t, const optional<_Tp>& __x) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator<(nullopt_t, const optional<_Tp>& __x) noexcept { - return static_cast(__x); + return static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator<=(const optional<_Tp>& __x, nullopt_t) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator<=(const optional<_Tp>& __x, nullopt_t) noexcept { - return !static_cast(__x); + return !static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator<=(nullopt_t, const optional<_Tp>&) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator<=(nullopt_t, const optional<_Tp>&) noexcept { - return true; + return true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator>(const optional<_Tp>& __x, nullopt_t) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator>(const optional<_Tp>& __x, nullopt_t) noexcept { - return static_cast(__x); + return static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator>(nullopt_t, const optional<_Tp>&) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator>(nullopt_t, const optional<_Tp>&) noexcept { - return false; + return false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator>=(const optional<_Tp>&, nullopt_t) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator>=(const optional<_Tp>&, nullopt_t) noexcept { - return true; + return true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator>=(nullopt_t, const optional<_Tp>& __x) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator>=(nullopt_t, const optional<_Tp>& __x) noexcept { - return !static_cast(__x); + return !static_cast(__x); } // Comparisons with T template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() == - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() == declval()), bool), + bool> operator==(const optional<_Tp>& __x, const _Up& __v) { - return static_cast(__x) ? *__x == __v : false; + return static_cast(__x) ? *__x == __v : false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() == - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() == declval()), bool), + bool> operator==(const _Tp& __v, const optional<_Up>& __x) { - return static_cast(__x) ? __v == *__x : false; + return static_cast(__x) ? __v == *__x : false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() != - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() != declval()), bool), + bool> operator!=(const optional<_Tp>& __x, const _Up& __v) { - return static_cast(__x) ? *__x != __v : true; + return static_cast(__x) ? *__x != __v : true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() != - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() != declval()), bool), + bool> operator!=(const _Tp& __v, const optional<_Up>& __x) { - return static_cast(__x) ? __v != *__x : true; + return static_cast(__x) ? __v != *__x : true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() < - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() < declval()), bool), + bool> operator<(const optional<_Tp>& __x, const _Up& __v) { - return static_cast(__x) ? *__x < __v : true; + return static_cast(__x) ? *__x < __v : true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() < - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() < declval()), bool), + bool> operator<(const _Tp& __v, const optional<_Up>& __x) { - return static_cast(__x) ? __v < *__x : false; + return static_cast(__x) ? __v < *__x : false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() <= - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() <= declval()), bool), + bool> operator<=(const optional<_Tp>& __x, const _Up& __v) { - return static_cast(__x) ? *__x <= __v : true; + return static_cast(__x) ? *__x <= __v : true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() <= - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() <= declval()), bool), + bool> operator<=(const _Tp& __v, const optional<_Up>& __x) { - return static_cast(__x) ? __v <= *__x : false; + return static_cast(__x) ? __v <= *__x : false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() > - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() > declval()), bool), + bool> operator>(const optional<_Tp>& __x, const _Up& __v) { - return static_cast(__x) ? *__x > __v : false; + return static_cast(__x) ? *__x > __v : false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() > - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() > declval()), bool), + bool> operator>(const _Tp& __v, const optional<_Up>& __x) { - return static_cast(__x) ? __v > *__x : true; + return static_cast(__x) ? __v > *__x : true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() >= - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() >= declval()), bool), + bool> operator>=(const optional<_Tp>& __x, const _Up& __v) { - return static_cast(__x) ? *__x >= __v : false; + return static_cast(__x) ? *__x >= __v : false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() >= - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() >= declval()), bool), + bool> operator>=(const _Tp& __v, const optional<_Up>& __x) { - return static_cast(__x) ? __v >= *__x : true; + return static_cast(__x) ? __v >= *__x : true; } - template -inline _LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_move_constructible, _Tp) && _LIBCUDACXX_TRAIT(is_swappable, _Tp), - void -> +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_move_constructible, _Tp) && _LIBCUDACXX_TRAIT(is_swappable, _Tp), + void> swap(optional<_Tp>& __x, optional<_Tp>& __y) noexcept(noexcept(__x.swap(__y))) { - __x.swap(__y); + __x.swap(__y); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -optional> make_optional(_Tp&& __v) +_LIBCUDACXX_INLINE_VISIBILITY constexpr optional> make_optional(_Tp&& __v) { - return optional>(_CUDA_VSTD::forward<_Tp>(__v)); + return optional>(_CUDA_VSTD::forward<_Tp>(__v)); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -optional<_Tp> make_optional(_Args&&... __args) +_LIBCUDACXX_INLINE_VISIBILITY constexpr optional<_Tp> make_optional(_Args&&... __args) { - return optional<_Tp>(in_place, _CUDA_VSTD::forward<_Args>(__args)...); + return optional<_Tp>(in_place, _CUDA_VSTD::forward<_Args>(__args)...); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -optional<_Tp> make_optional(initializer_list<_Up> __il, _Args&&... __args) +_LIBCUDACXX_INLINE_VISIBILITY constexpr optional<_Tp> make_optional(initializer_list<_Up> __il, _Args&&... __args) { - return optional<_Tp>(in_place, __il, _CUDA_VSTD::forward<_Args>(__args)...); + return optional<_Tp>(in_place, __il, _CUDA_VSTD::forward<_Args>(__args)...); } -#ifndef __cuda_std__ +# ifndef __cuda_std__ template -struct _LIBCUDACXX_TEMPLATE_VIS hash< - __enable_hash_helper, remove_const_t<_Tp>> -> +struct _LIBCUDACXX_TEMPLATE_VIS hash<__enable_hash_helper, remove_const_t<_Tp>>> { -#if _CCCL_STD_VER <= 2017 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) - _LIBCUDACXX_DEPRECATED_IN_CXX17 typedef optional<_Tp> argument_type; - _LIBCUDACXX_DEPRECATED_IN_CXX17 typedef size_t result_type; -#endif +# if _CCCL_STD_VER <= 2017 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + _LIBCUDACXX_DEPRECATED_IN_CXX17 typedef optional<_Tp> argument_type; + _LIBCUDACXX_DEPRECATED_IN_CXX17 typedef size_t result_type; +# endif - _LIBCUDACXX_INLINE_VISIBILITY - size_t operator()(const optional<_Tp>& __opt) const - { - return static_cast(__opt) ? hash>()(*__opt) : 0; - } + _LIBCUDACXX_INLINE_VISIBILITY size_t operator()(const optional<_Tp>& __opt) const + { + return static_cast(__opt) ? hash>()(*__opt) : 0; + } }; -#endif // __cuda_std__ +# endif // __cuda_std__ _LIBCUDACXX_END_NAMESPACE_STD