|
4636 | 4636 |
|
4637 | 4637 | \rSec1[exec.util]{Sender/receiver utilities}
|
4638 | 4638 |
|
| 4639 | +\rSec2[exec.util.cmplsig]{\tcode{execution::completion_signatures}} |
| 4640 | + |
| 4641 | +\pnum |
| 4642 | +\tcode{completion_signatures} is a type |
| 4643 | +that encodes a set of completion signatures\iref{exec.async.ops}. |
| 4644 | + |
| 4645 | +\pnum |
| 4646 | +\begin{example} |
| 4647 | +\begin{codeblock} |
| 4648 | +struct my_sender { |
| 4649 | + using sender_concept = sender_t; |
| 4650 | + using completion_signatures = |
| 4651 | + execution::completion_signatures< |
| 4652 | + set_value_t(), |
| 4653 | + set_value_t(int, float), |
| 4654 | + set_error_t(exception_ptr), |
| 4655 | + set_error_t(error_code), |
| 4656 | + set_stopped_t()>; |
| 4657 | +}; |
| 4658 | +\end{codeblock} |
| 4659 | +Declares \tcode{my_sender} to be a sender |
| 4660 | +that can complete by calling one of the following |
| 4661 | +for a receiver expression \tcode{rcvr}: |
| 4662 | +\begin{itemize} |
| 4663 | +\item \tcode{set_value(rcvr)} |
| 4664 | +\item \tcode{set_value(rcvr, int\{...\}, float\{...\})} |
| 4665 | +\item \tcode{set_error(rcvr, exception_ptr\{...\})} |
| 4666 | +\item \tcode{set_error(rcvr, error_code\{...\})} |
| 4667 | +\item \tcode{set_stopped(rcvr)} |
| 4668 | +\end{itemize} |
| 4669 | +\end{example} |
| 4670 | + |
| 4671 | +\pnum |
| 4672 | +This subclause makes use of the following exposition-only entities: |
| 4673 | +\begin{codeblock} |
| 4674 | +template<class Fn> |
| 4675 | + concept @\defexposconcept{completion-signature}@ = @\seebelow@; |
| 4676 | +\end{codeblock} |
| 4677 | + |
| 4678 | +\pnum |
| 4679 | +A type \tcode{Fn} satisfies \exposconcept{completion-signature} |
| 4680 | +if and only if it is a function type with one of the following forms: |
| 4681 | +\begin{itemize} |
| 4682 | +\item |
| 4683 | +\tcode{set_value_t(Vs...)}, |
| 4684 | +where \tcode{Vs} is a pack of object or reference types. |
| 4685 | +\item |
| 4686 | +\tcode{set_error_t(Err)}, |
| 4687 | +where \tcode{Err} is an object or reference type. |
| 4688 | +\item |
| 4689 | +\tcode{set_stopped_t()} |
| 4690 | +\end{itemize} |
| 4691 | + |
| 4692 | +\pnum |
| 4693 | +\begin{codeblock} |
| 4694 | +template<bool> |
| 4695 | + struct @\exposid{indirect-meta-apply}@ { |
| 4696 | + template<template<class...> class T, class... As> |
| 4697 | + using @\exposid{meta-apply}@ = T<As...>; // \expos |
| 4698 | + }; |
| 4699 | + |
| 4700 | +template<class...> |
| 4701 | + concept @\defexposconcept{always-true}@ = true; // \expos |
| 4702 | + |
| 4703 | +template<class Tag, |
| 4704 | + @\exposconcept{valid-completion-signatures}@ Completions, |
| 4705 | + template<class...> class Tuple, |
| 4706 | + template<class...> class Variant> |
| 4707 | + using @\exposid{gather-signatures}@ = @\seebelow@; |
| 4708 | +\end{codeblock} |
| 4709 | + |
| 4710 | +\pnum |
| 4711 | +Let \tcode{Fns} be a pack of the arguments of |
| 4712 | +the \tcode{completion_signatures} specialization named by \tcode{Completions}, |
| 4713 | +let \tcode{TagFns} be a pack of the function types in \tcode{Fns} |
| 4714 | +whose return types are \tcode{Tag}, and |
| 4715 | +let $\tcode{Ts}_n$ be a pack of the function argument types |
| 4716 | +in the $n$-th type in \tcode{TagFns}. |
| 4717 | +Then, given two variadic templates \tcode{Tuple} and \tcode{Variant}, |
| 4718 | +the type \tcode{\exposid{gather-signatures}<Tag, Completions, Tuple, Variant>} |
| 4719 | +names the type |
| 4720 | +\begin{codeblock} |
| 4721 | +@\exposid{META-APPLY}@(Variant, @\exposid{META-APPLY}@(Tuple, Ts@$_0$@...), |
| 4722 | + @\exposid{META-APPLY}@(Tuple, Ts@$_1$@...), |
| 4723 | + @\ldots@, |
| 4724 | + @\exposid{META-APPLY}@(Tuple, Ts@$_{m-1}$@...)) |
| 4725 | +\end{codeblock} |
| 4726 | +where $m$ is the size of the pack \tcode{TagFns} and |
| 4727 | +\tcode{META-APPLY(T, As...)} is equivalent to: |
| 4728 | +\begin{codeblock} |
| 4729 | +typename @\exposid{indirect-meta-apply}@<@\exposid{always-true}@<As...>>::template @\exposid{meta-apply}@<T, As...> |
| 4730 | +\end{codeblock} |
| 4731 | + |
| 4732 | +\pnum |
| 4733 | +\begin{note} |
| 4734 | +The purpose of \exposid{META-APPLY} is to make it valid |
| 4735 | +to use non-variadic templates as \tcode{Variant} and \tcode{Tuple} arguments |
| 4736 | +to \exposid{gather-signatures}. |
| 4737 | +\end{note} |
| 4738 | + |
| 4739 | +\pnum |
| 4740 | +\begin{codeblock} |
| 4741 | +namespace std::execution { |
| 4742 | + template<@\exposconcept{completion-signature}@... Fns> |
| 4743 | + struct completion_signatures {}; |
| 4744 | + |
| 4745 | + template<class Sndr, |
| 4746 | + class Env = empty_env, |
| 4747 | + template<class...> class Tuple = @\exposid{decayed-tuple}@, |
| 4748 | + template<class...> class Variant = @\exposid{variant-or-empty}@> |
| 4749 | + requires @\libconcept{sender_in}@<Sndr, Env> |
| 4750 | + using value_types_of_t = |
| 4751 | + @\exposid{gather-signatures}@<set_value_t, completion_signatures_of_t<Sndr, Env>, Tuple, Variant>; |
| 4752 | + |
| 4753 | + template<class Sndr, |
| 4754 | + class Env = empty_env, |
| 4755 | + template<class...> class Variant = @\exposid{variant-or-empty}@> |
| 4756 | + requires @\libconcept{sender_in}@<Sndr, Env> |
| 4757 | + using error_types_of_t = |
| 4758 | + @\exposid{gather-signatures}@<set_error_t, completion_signatures_of_t<Sndr, Env>, |
| 4759 | + type_identity_t, Variant>; |
| 4760 | + |
| 4761 | + template<class Sndr, class Env = empty_env> |
| 4762 | + requires @\libconcept{sender_in}@<Sndr, Env> |
| 4763 | + inline constexpr bool sends_stopped = |
| 4764 | + !@\libconcept{same_as}@<@\exposid{type-list}@<>, |
| 4765 | + @\exposid{gather-signatures}@<set_stopped_t, completion_signatures_of_t<Sndr, Env>, |
| 4766 | + @\exposid{type-list}@, @\exposid{type-list}@>>; |
| 4767 | +} |
| 4768 | +\end{codeblock} |
| 4769 | + |
| 4770 | +\rSec2[exec.util.cmplsig.trans]{execution::transform_completion_signatures} |
| 4771 | + |
| 4772 | +\pnum |
| 4773 | +\tcode{transform_completion_signatures} is an alias template |
| 4774 | +used to transform one set of completion signatures into another. |
| 4775 | +It takes a set of completion signatures and |
| 4776 | +several other template arguments |
| 4777 | +that apply modifications to each completion signature in the set |
| 4778 | +to generate a new specialization of \tcode{completion_signature}s. |
| 4779 | +\pnum |
| 4780 | +\begin{example} |
| 4781 | +Given a sender \tcode{Sndr} and an environment \tcode{Env}, |
| 4782 | +adapt the completion signatures of \tcode{Sndr} by |
| 4783 | +lvalue-ref qualifying the values, |
| 4784 | +adding an additional \tcode{exception_ptr} error completion |
| 4785 | +if its not already there, and |
| 4786 | +leaving the other completion signatures alone. |
| 4787 | +\begin{codeblock} |
| 4788 | +template<class... Args> |
| 4789 | + using my_set_value_t = |
| 4790 | + completion_signatures< |
| 4791 | + set_value_t(add_lvalue_reference_t<Args>...)>; |
| 4792 | + |
| 4793 | +using my_completion_signatures = |
| 4794 | + transform_completion_signatures< |
| 4795 | + completion_signatures_of_t<Sndr, Env>, |
| 4796 | + completion_signatures<set_error_t(exception_ptr)>, |
| 4797 | + my_set_value_t>; |
| 4798 | +\end{codeblock} |
| 4799 | +\end{example} |
| 4800 | + |
| 4801 | +\pnum |
| 4802 | +This subclause makes use of the following exposition-only entities: |
| 4803 | +\begin{codeblock} |
| 4804 | +template<class... As> |
| 4805 | + using default-set-value = |
| 4806 | + completion_signatures<set_value_t(As...)>; |
| 4807 | + |
| 4808 | +template<class Err> |
| 4809 | + using default-set-error = |
| 4810 | + completion_signatures<set_error_t(Err)>; |
| 4811 | +\end{codeblock} |
| 4812 | + |
| 4813 | +\pnum |
| 4814 | +\begin{codeblock} |
| 4815 | +namespace std::execution { |
| 4816 | + template<@\exposconcept{valid-completion-signatures}@ InputSignatures, |
| 4817 | + @\exposconcept{valid-completion-signatures}@ AdditionalSignatures = completion_signatures<>, |
| 4818 | + template<class...> class SetValue = @\exposid{default-set-value}@, |
| 4819 | + template<class> class SetError = @\exposid{default-set-error}@, |
| 4820 | + @\exposconcept{valid-completion-signatures}@ SetStopped = completion_signatures<set_stopped_t()>> |
| 4821 | + using transform_completion_signatures = completion_signatures<@\seebelow@>; |
| 4822 | +} |
| 4823 | +\end{codeblock} |
| 4824 | + |
| 4825 | +\pnum |
| 4826 | +\tcode{SetValue} shall name an alias template |
| 4827 | +such that for any pack of types \tcode{As}, |
| 4828 | +the type \tcode{SetValue<As...>} is either ill-formed or else |
| 4829 | +\tcode{\exposconcept{valid-completion-signatures}<SetValue<As...>>} is satisfied. |
| 4830 | +\tcode{SetError} shall name an alias template |
| 4831 | +such that for any type \tcode{Err}, |
| 4832 | +\tcode{SetError<Err>} is either ill-formed or else |
| 4833 | +\tcode{\exposconcept{valid-completion-signatures}<SetError<Err>>} is satisfied. |
| 4834 | + |
| 4835 | +\pnum |
| 4836 | +Let \tcode{Vs} be a pack of the types in the \exposid{type-list} named by |
| 4837 | +\tcode{\exposid{gather-signatures}<set_value_t, InputSigna\-tures, SetValue, \exposid{type-list}>}. |
| 4838 | + |
| 4839 | +\pnum |
| 4840 | +Let \tcode{Es} be a pack of the types in the \exposid{type-list} named by |
| 4841 | +\tcode{\exposid{gather-signatures}<set_error_t, InputSigna\-tures, type_identity_t, \exposid{error-list}>}, |
| 4842 | +where \exposid{error-list} is an alias template |
| 4843 | +such that \tcode{\exposid{error-list}<\linebreak Ts...>} is |
| 4844 | +\tcode{\exposid{type-list}<SetError<Ts>...>}. |
| 4845 | + |
| 4846 | +\pnum |
| 4847 | +Let \tcode{Ss} name the type \tcode{completion_signatures<>} if |
| 4848 | +\tcode{\exposid{gather-signatures}<set_stopped_t, InputSigna\-tures, \exposid{type-list}, \exposid{type-list}>} |
| 4849 | +is an alias for the type \tcode{\exposid{type-list}<>}; |
| 4850 | +otherwise, \tcode{SetStopped}. |
| 4851 | + |
| 4852 | +\pnum |
| 4853 | +If any of the above types are ill-formed, |
| 4854 | +then |
| 4855 | +\begin{codeblock} |
| 4856 | +transform_completion_signatures<InputSignatures, AdditionalSignatures, |
| 4857 | + SetValue, SetError, SetStopped> |
| 4858 | +\end{codeblock} |
| 4859 | +is ill-formed. |
| 4860 | +Otherwise, |
| 4861 | +\begin{codeblock} |
| 4862 | +transform_completion_signatures<InputSignatures, AdditionalSignatures, |
| 4863 | + SetValue, SetError, SetStopped> |
| 4864 | +\end{codeblock} |
| 4865 | +is the type \tcode{completion_signatures<Sigs...>} |
| 4866 | +where \tcode{Sigs...} is the unique set of types in all the template arguments |
| 4867 | +of all the \tcode{completion_signatures} specializations in the set |
| 4868 | +\tcode{AdditionalSignatures}, \tcode{Vs...}, \tcode{Es...}, \tcode{Ss}. |
| 4869 | + |
4639 | 4870 | \rSec1[exec.ctx]{Execution contexts}
|
4640 | 4871 |
|
4641 | 4872 | \rSec1[exec.coro.util]{Coroutine utilities}
|
0 commit comments