Skip to content

P3503R3 Make type-erased allocator use in promise and packaged_task c… #7993

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
63 changes: 38 additions & 25 deletions source/threads.tex
Original file line number Diff line number Diff line change
Expand Up @@ -10724,9 +10724,6 @@
void set_value_at_thread_exit(@\seebelow@);
void set_exception_at_thread_exit(exception_ptr p);
};

template<class R, class Alloc>
struct uses_allocator<promise<R>, Alloc>;
}
\end{codeblock}

Expand All @@ -10746,20 +10743,6 @@
they acquire a single mutex associated with the promise object while updating the
promise object.

\indexlibrarymember{uses_allocator}{promise}%
\begin{itemdecl}
template<class R, class Alloc>
struct uses_allocator<promise<R>, Alloc>
: true_type { };
\end{itemdecl}

\begin{itemdescr}
\pnum
\expects
\tcode{Alloc} meets
the \oldconcept{Allocator} requirements\iref{allocator.requirements.general}.
\end{itemdescr}

\indexlibraryctor{promise}%
\begin{itemdecl}
promise();
Expand Down Expand Up @@ -11861,6 +11844,8 @@
packaged_task() noexcept;
template<class F>
explicit packaged_task(F&& f);
template<class F, class Allocator>
explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f);
~packaged_task();

// no copy
Expand Down Expand Up @@ -11910,6 +11895,19 @@
explicit packaged_task(F&& f);
\end{itemdecl}

\begin{itemdescr}
\pnum
\effects
Equivalent to
\tcode{packaged_task(allocator_arg, allocator<int>(), std::forward<F>(f))}.
\end{itemdescr}

\indexlibraryctor{packaged_task}%
\begin{itemdecl}
template<class F, class Allocator>
explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f);
\end{itemdecl}

\begin{itemdescr}
\pnum
\constraints
Expand All @@ -11920,17 +11918,27 @@
\mandates
\tcode{is_invocable_r_v<R, decay_t<F>\&, ArgTypes...>} is \tcode{true}.

\pnum
\expects
\tcode{Allocator} meets the \oldconcept{Allocator} requirements\iref{allocator.requirements.general}.

\pnum
\effects
Let \tcode{A2} be
\tcode{allocator_traits<Allocator>::rebind_alloc<\unspec>}
and let \tcode{a2} be an object of type \tcode{A2} initialized with
\tcode{A2(a)}.
Constructs a new \tcode{packaged_task} object with
a stored task of type \tcode{decay_t<F>} and a shared state.
Initializes the object's stored task with \tcode{std::forward<F>(f)}.
Uses \tcode{a2} to allocate storage for the shared state and stores a copy
of \tcode{a2} in the shared state.

\pnum
\throws
Any exceptions thrown by the copy or move constructor of \tcode{f}, or
\tcode{bad_alloc} if memory for the internal data structures
cannot be allocated.
Any exceptions thrown by the initialization of the stored task.
If storage for the shared state cannot be allocated, any exception thrown by
\tcode{A2::allocate}.
\end{itemdescr}

\indexlibraryctor{packaged_task}%
Expand Down Expand Up @@ -12140,9 +12148,16 @@
\begin{itemdescr}
\pnum
\effects
As if \tcode{*this = packaged_task(std::move(f))}, where
Equivalent to:
\begin{codeblock}
if (!valid())
throw future_error(future_errc::no_state);
*this = packaged_task(allocator_arg, a, std::move(f));
\end{codeblock}
where
\tcode{f} is the task stored in
\tcode{*this}.
\tcode{*this}
and \tcode{a} is the allocator stored in the shared state.
\begin{note}
This constructs a new shared state for \tcode{*this}. The
old state is abandoned\iref{futures.state}.
Expand All @@ -12151,9 +12166,7 @@
\pnum
\throws
\begin{itemize}
\item \tcode{bad_alloc} if memory for the new shared state cannot be allocated.
\item Any exception thrown by the move constructor of the task stored in the shared
state.
\item Any exception thrown by the \tcode{packaged_task} constructor.
\item \tcode{future_error} with an error condition of \tcode{no_state} if \tcode{*this}
has no shared state.
\end{itemize}
Expand Down