Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<future> cleanups #3940

Merged
merged 7 commits into from
Sep 21, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 12 additions & 40 deletions stl/inc/future
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,6 @@ public:
using _Mybase = _Associated_state<_Ret>;
using _Mydel = typename _Mybase::_Mydel;

template <class _Fty2>
_Packaged_state(const _Fty2& _Fnarg) : _Fn(_Fnarg) {}

#if _HAS_FUNCTION_ALLOCATOR_SUPPORT
template <class _Fty2, class _Alloc>
_Packaged_state(const _Fty2& _Fnarg, const _Alloc& _Al, _Mydel* _Dp)
: _Mybase(_Dp), _Fn(allocator_arg, _Al, _Fnarg) {}
#endif // _HAS_FUNCTION_ALLOCATOR_SUPPORT

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are fully replaceable with their _Fty2&& versions

template <class _Fty2>
_Packaged_state(_Fty2&& _Fnarg) : _Fn(_STD forward<_Fty2>(_Fnarg)) {}

Expand Down Expand Up @@ -507,7 +498,7 @@ public:
_CATCH_END
}

const function<_Ret(_ArgTypes...)>& _Get_fn() {
const auto& _Get_fn() const {
return _Fn;
}

Expand All @@ -522,15 +513,6 @@ public:
using _Mybase = _Associated_state<_Ret*>;
using _Mydel = typename _Mybase::_Mydel;

template <class _Fty2>
_Packaged_state(const _Fty2& _Fnarg) : _Fn(_Fnarg) {}

#if _HAS_FUNCTION_ALLOCATOR_SUPPORT
template <class _Fty2, class _Alloc>
_Packaged_state(const _Fty2& _Fnarg, const _Alloc& _Al, _Mydel* _Dp)
: _Mybase(_Dp), _Fn(allocator_arg, _Al, _Fnarg) {}
#endif // _HAS_FUNCTION_ALLOCATOR_SUPPORT

template <class _Fty2>
_Packaged_state(_Fty2&& _Fnarg) : _Fn(_STD forward<_Fty2>(_Fnarg)) {}

Expand Down Expand Up @@ -560,7 +542,7 @@ public:
_CATCH_END
}

const function<_Ret&(_ArgTypes...)>& _Get_fn() {
const auto& _Get_fn() const {
return _Fn;
}

Expand All @@ -575,15 +557,6 @@ public:
using _Mybase = _Associated_state<int>;
using _Mydel = typename _Mybase::_Mydel;

template <class _Fty2>
_Packaged_state(const _Fty2& _Fnarg) : _Fn(_Fnarg) {}

#if _HAS_FUNCTION_ALLOCATOR_SUPPORT
template <class _Fty2, class _Alloc>
_Packaged_state(const _Fty2& _Fnarg, const _Alloc& _Al, _Mydel* _Dp)
: _Mybase(_Dp), _Fn(allocator_arg, _Al, _Fnarg) {}
#endif // _HAS_FUNCTION_ALLOCATOR_SUPPORT

template <class _Fty2>
_Packaged_state(_Fty2&& _Fnarg) : _Fn(_STD forward<_Fty2>(_Fnarg)) {}

Expand Down Expand Up @@ -615,7 +588,7 @@ public:
_CATCH_END
}

const function<void(_ArgTypes...)>& _Get_fn() {
const auto& _Get_fn() const {
return _Fn;
}

Expand Down Expand Up @@ -1285,12 +1258,13 @@ class packaged_task; // not defined
template <class _Ret, class... _ArgTypes>
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 <class _Fty2, enable_if_t<!is_same_v<_Remove_cvref_t<_Fty2>, packaged_task>, int> = 0>
Expand Down Expand Up @@ -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()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 80% sure about this change; or was the extra copy construction intentional here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe it was intentional.

_MyPromise._Get_state()._Abandon();
_MyPromise._Swap(_New_promise);
}
Expand Down Expand Up @@ -1385,14 +1358,13 @@ void swap(packaged_task<_Ty>& _Left, packaged_task<_Ty>& _Right) noexcept {
}

template <class... _Types, size_t... _Indices>
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 <class... _Types>
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
Comment on lines -1394 to +1367
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change requested: The difference here is that decltype(auto) won't SFINAE, but it appears that we don't need SFINAE here (nothing can directly ask is_invocable).

return _Invoke_stored_explicit(_STD move(_Tuple), index_sequence_for<_Types...>{});
}

Expand All @@ -1419,7 +1391,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));
}

Expand Down