From 4f97dbb4d6f1acd1be12c7b9bc6e3649e8082f72 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Fri, 22 Sep 2023 03:41:03 +0800 Subject: [PATCH] `` cleanups (#3940) --- stl/inc/future | 62 ++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 45 deletions(-) diff --git a/stl/inc/future b/stl/inc/future index 9f8c6b7d9..0d78943cb 100644 --- a/stl/inc/future +++ b/stl/inc/future @@ -469,15 +469,6 @@ public: using _Mybase = _Associated_state<_Ret>; using _Mydel = typename _Mybase::_Mydel; - template - _Packaged_state(const _Fty2& _Fnarg) : _Fn(_Fnarg) {} - -#if _HAS_FUNCTION_ALLOCATOR_SUPPORT - template - _Packaged_state(const _Fty2& _Fnarg, const _Alloc& _Al, _Mydel* _Dp) - : _Mybase(_Dp), _Fn(allocator_arg, _Al, _Fnarg) {} -#endif // _HAS_FUNCTION_ALLOCATOR_SUPPORT - template _Packaged_state(_Fty2&& _Fnarg) : _Fn(_STD forward<_Fty2>(_Fnarg)) {} @@ -507,7 +498,7 @@ public: _CATCH_END } - const function<_Ret(_ArgTypes...)>& _Get_fn() { + const auto& _Get_fn() const { return _Fn; } @@ -522,15 +513,6 @@ public: using _Mybase = _Associated_state<_Ret*>; using _Mydel = typename _Mybase::_Mydel; - template - _Packaged_state(const _Fty2& _Fnarg) : _Fn(_Fnarg) {} - -#if _HAS_FUNCTION_ALLOCATOR_SUPPORT - template - _Packaged_state(const _Fty2& _Fnarg, const _Alloc& _Al, _Mydel* _Dp) - : _Mybase(_Dp), _Fn(allocator_arg, _Al, _Fnarg) {} -#endif // _HAS_FUNCTION_ALLOCATOR_SUPPORT - template _Packaged_state(_Fty2&& _Fnarg) : _Fn(_STD forward<_Fty2>(_Fnarg)) {} @@ -560,7 +542,7 @@ public: _CATCH_END } - const function<_Ret&(_ArgTypes...)>& _Get_fn() { + const auto& _Get_fn() const { return _Fn; } @@ -575,15 +557,6 @@ public: using _Mybase = _Associated_state; using _Mydel = typename _Mybase::_Mydel; - template - _Packaged_state(const _Fty2& _Fnarg) : _Fn(_Fnarg) {} - -#if _HAS_FUNCTION_ALLOCATOR_SUPPORT - template - _Packaged_state(const _Fty2& _Fnarg, const _Alloc& _Al, _Mydel* _Dp) - : _Mybase(_Dp), _Fn(allocator_arg, _Al, _Fnarg) {} -#endif // _HAS_FUNCTION_ALLOCATOR_SUPPORT - template _Packaged_state(_Fty2&& _Fnarg) : _Fn(_STD forward<_Fty2>(_Fnarg)) {} @@ -615,7 +588,7 @@ public: _CATCH_END } - const function& _Get_fn() { + const auto& _Get_fn() const { return _Fn; } @@ -960,7 +933,7 @@ public: shared_future& operator=(const shared_future&) = default; - shared_future(future<_Ty>&& _Other) noexcept : _Mybase(_STD forward<_Mybase>(_Other)) {} + shared_future(future<_Ty>&& _Other) noexcept : _Mybase(static_cast<_Mybase&&>(_Other)) {} shared_future(shared_future&& _Other) noexcept : _Mybase(_STD move(_Other)) {} @@ -985,7 +958,7 @@ public: shared_future& operator=(const shared_future&) = default; - shared_future(future<_Ty&>&& _Other) noexcept : _Mybase(_STD forward<_Mybase>(_Other)) {} + shared_future(future<_Ty&>&& _Other) noexcept : _Mybase(static_cast<_Mybase&&>(_Other)) {} shared_future(shared_future&& _Other) noexcept : _Mybase(_STD move(_Other)) {} @@ -1012,7 +985,7 @@ public: shared_future(shared_future&& _Other) noexcept : _Mybase(_STD move(_Other)) {} - shared_future(future&& _Other) noexcept : _Mybase(_STD forward<_Mybase>(_Other)) {} + shared_future(future&& _Other) noexcept : _Mybase(static_cast<_Mybase&&>(_Other)) {} shared_future& operator=(shared_future&&) = default; @@ -1285,12 +1258,13 @@ class packaged_task; // not defined template class packaged_task<_Ret(_ArgTypes...)> { // class that defines an asynchronous provider that returns the result of a call to a function object -public: +private: using _Ptype = typename _P_arg_type<_Ret>::type; using _MyPromiseType = _Promise<_Ptype>; using _MyStateManagerType = _State_manager<_Ptype>; using _MyStateType = _Packaged_state<_Ret(_ArgTypes...)>; +public: packaged_task() = default; template , packaged_task>, int> = 0> @@ -1347,10 +1321,9 @@ public: } void reset() { // reset to newly constructed state - _MyStateManagerType& _State = _MyPromise._Get_state_for_set(); - _MyStateType* _MyState = static_cast<_MyStateType*>(_State._Ptr()); - function<_Ret(_ArgTypes...)> _Fnarg = _MyState->_Get_fn(); - _MyPromiseType _New_promise(new _MyStateType(_Fnarg)); + _MyStateManagerType& _State = _MyPromise._Get_state_for_set(); + _MyStateType* _MyState = static_cast<_MyStateType*>(_State._Ptr()); + _MyPromiseType _New_promise(new _MyStateType(_MyState->_Get_fn())); _MyPromise._Get_state()._Abandon(); _MyPromise._Swap(_New_promise); } @@ -1385,14 +1358,13 @@ void swap(packaged_task<_Ty>& _Left, packaged_task<_Ty>& _Right) noexcept { } template -auto _Invoke_stored_explicit(tuple<_Types...>&& _Tuple, index_sequence<_Indices...>) -> decltype(_STD invoke( - _STD get<_Indices>(_STD move(_Tuple))...)) { // invoke() a tuple with explicit parameter ordering +decltype(auto) _Invoke_stored_explicit( + tuple<_Types...>&& _Tuple, index_sequence<_Indices...>) { // invoke() a tuple with explicit parameter ordering return _STD invoke(_STD get<_Indices>(_STD move(_Tuple))...); } template -auto _Invoke_stored(tuple<_Types...>&& _Tuple) - -> decltype(_Invoke_stored_explicit(_STD move(_Tuple), index_sequence_for<_Types...>{})) { // invoke() a tuple +decltype(auto) _Invoke_stored(tuple<_Types...>&& _Tuple) { // invoke() a tuple return _Invoke_stored_explicit(_STD move(_Tuple), index_sequence_for<_Types...>{}); } @@ -1400,7 +1372,7 @@ template class _Fake_no_copy_callable_adapter { // async() is built on packaged_task internals which incorrectly use // std::function, which requires that things be copyable. We can't fix this in an - // update, so this adapter turns copies into terminate(). When VSO-153581 is + // update, so this adapter turns copies into abort(). When VSO-153581 is // fixed, remove this adapter. private: using _Storaget = tuple...>; @@ -1412,14 +1384,14 @@ public: [[noreturn]] _Fake_no_copy_callable_adapter(const _Fake_no_copy_callable_adapter& _Other) : _Storage(_STD move(_Other._Storage)) { - _CSTD abort(); // shouldn't be called, see GH-3888 + _CSTD abort(); // shouldn't be called } _Fake_no_copy_callable_adapter(_Fake_no_copy_callable_adapter&& _Other) = default; _Fake_no_copy_callable_adapter& operator=(const _Fake_no_copy_callable_adapter&) = delete; _Fake_no_copy_callable_adapter& operator=(_Fake_no_copy_callable_adapter&&) = delete; - auto operator()() -> decltype(_Invoke_stored(_STD move(_STD declval<_Storaget&>()))) { + decltype(auto) operator()() { return _Invoke_stored(_STD move(_Storage)); }