From 86b16ce889fd682db4dfbe938189d8a2b486137d Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Wed, 9 Aug 2023 19:58:08 +0800 Subject: [PATCH 1/7] replace `auto->long expr` with `decltype(auto)` --- stl/inc/future | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/stl/inc/future b/stl/inc/future index 9f8c6b7d9b..087cc03dbb 100644 --- a/stl/inc/future +++ b/stl/inc/future @@ -1385,14 +1385,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...>{}); } @@ -1419,7 +1418,7 @@ public: _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)); } From f8b81b0c30d719f141b5a63c7fe438ed106d8410 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Wed, 9 Aug 2023 20:29:35 +0800 Subject: [PATCH 2/7] `_Packaged_state(const auto&)` ctors are useless --- stl/inc/future | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/stl/inc/future b/stl/inc/future index 087cc03dbb..583fa9120f 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)) {} @@ -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)) {} @@ -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)) {} From 8cf48773eba47e476712f15b4e8f4e0c603ab9a9 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Wed, 9 Aug 2023 20:47:19 +0800 Subject: [PATCH 3/7] around `_Get_fn`; remove an extra copy construction (was `ctor(const&) then ctor(&)` now `ctor(const&)`) --- stl/inc/future | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/stl/inc/future b/stl/inc/future index 583fa9120f..ed8d43fde4 100644 --- a/stl/inc/future +++ b/stl/inc/future @@ -498,7 +498,7 @@ public: _CATCH_END } - const function<_Ret(_ArgTypes...)>& _Get_fn() { + const auto& _Get_fn() const { return _Fn; } @@ -542,7 +542,7 @@ public: _CATCH_END } - const function<_Ret&(_ArgTypes...)>& _Get_fn() { + const auto& _Get_fn() const { return _Fn; } @@ -588,7 +588,7 @@ public: _CATCH_END } - const function& _Get_fn() { + const auto& _Get_fn() const { return _Fn; } @@ -1322,8 +1322,7 @@ 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)); + _MyPromiseType _New_promise(new _MyStateType(_MyState->_Get_fn())); _MyPromise._Get_state()._Abandon(); _MyPromise._Swap(_New_promise); } From f6fc01f24314e462243363e787f77243e1e71b3b Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Wed, 9 Aug 2023 21:00:22 +0800 Subject: [PATCH 4/7] hide some typedefs in `packaged_task` --- stl/inc/future | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/stl/inc/future b/stl/inc/future index ed8d43fde4..6b71bf168b 100644 --- a/stl/inc/future +++ b/stl/inc/future @@ -1258,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> @@ -1320,8 +1321,8 @@ public: } void reset() { // reset to newly constructed state - _MyStateManagerType& _State = _MyPromise._Get_state_for_set(); - _MyStateType* _MyState = static_cast<_MyStateType*>(_State._Ptr()); + _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); From e8b528c03485d64153b335ba6e8249e0189d3ee7 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Fri, 11 Aug 2023 12:32:49 +0800 Subject: [PATCH 5/7] comment fix --- stl/inc/future | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/future b/stl/inc/future index 6b71bf168b..bb26e3a218 100644 --- a/stl/inc/future +++ b/stl/inc/future @@ -1372,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...>; From 9327f046e6206720118b4b34cffa6f6f9fc8cd38 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Wed, 6 Sep 2023 15:51:37 +0800 Subject: [PATCH 6/7] replace uncommon `forward` patterns --- stl/inc/future | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/inc/future b/stl/inc/future index bb26e3a218..65eed13cc7 100644 --- a/stl/inc/future +++ b/stl/inc/future @@ -933,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)) {} @@ -958,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)) {} @@ -985,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; From afd9d6f77c307ee13e5f6ef956bce66c31fff7eb Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Wed, 6 Sep 2023 15:52:45 +0800 Subject: [PATCH 7/7] nitpick on my previous pr --- stl/inc/future | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/future b/stl/inc/future index 65eed13cc7..0d78943cbb 100644 --- a/stl/inc/future +++ b/stl/inc/future @@ -1384,7 +1384,7 @@ 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;