std::experi...al::when_any(3)
okay so bestie, we're in the C++ Standard Libary manual and today's main character is std::experimental::when_any. yes, that's the actual manual name up top β we don't make the rules π
πΈ NAME πΈ
std::experimental::when_any β std::experimental::when_any
periodt. that's the name, no notes π
π¦ Synopsis π¦
Defined in header <experimental/future>
template< class Sequence >
struct when_any_result {
(concurrency
std::size_t index;
TS)
Sequence futures;
};
template< class InputIt >
auto when_any( InputIt first, InputIt last )
(1) (concurrency
TS)
-> future<when_any_result<std::vector<typename
std::iterator_traits<InputIt>::value_type>>>;
template< class... Futures >
auto when_any( Futures&&... futures )
(2) (concurrency
TS)
->
future<when_any_result<std::tuple<std::decay_t<Futures>...>>>;
so what this does is create a future object that becomes ready when at least one of the input futures and shared_futures becomes ready. π«Ά
π¨ Undefined behavior alert: the behavior is undefined if any inputfutureorshared_futureis invalid. do not play with invalid futures, bestie π
in particular, let Sequence be std::vector<typename std::iterator_traits<InputIt>::value_type> for (1) and std::tuple<std::decay_t<Futures>...> for (2). this function template creates a shared state containing when_any_result<Sequence> and returns a future referring to the shared state. β¨
every input future is moved into the corresponding object in the futures member of the when_any_result<Sequence> in the shared state, and every input shared_future is copied to the corresponding object in the futures member of the when_any_result<Sequence> in the shared state. the order of the objects in the Sequence matches the order of arguments. no cap π₯
now the overload-resolution gatekeeping, because of course there's gatekeeping:
- this function does not participate in overload resolution unless
InputIt's value type (i.e.,typename std::iterator_traits<InputIt>::value_type) is astd::experimental::futureorstd::experimental::shared_future. π - this function does not participate in overload resolution unless every argument is either a (possibly cv-qualified)
std::experimental::shared_futureor a cv-unqualifiedstd::experimental::future. (Formally, for every typeFninFutures, eitherstd::remove_reference_t<Fn>isstd::experimental::future<Rn>, orstd::decay_t<Fn>isstd::experimental::shared_future<Rn>.) π
after this call, every input future is no longer valid; every input shared_future remains valid. iconic behavior honestly π
π Return value π
a future referring to the shared state created by the call. the future is always valid(), and it becomes ready when at least one of the input futures and shared_futures the call has is ready. the index member of the when_any_result contains the position of the ready future or shared_future in the futures member. π
- if the range is empty (i.e.,
first == last), the returnedfutureis ready immediately; thefuturesfield of thewhen_any_resultis an empty vector, and theindexfield issize_t(-1). π - if no argument is provided, the returned
futureis ready immediately; thefuturesfield of thewhen_any_resultis an empty tuple, and theindexfield issize_t(-1). π§
okay that's the whole page, bestie π«Ά this lil transmission came from source/version http://cppreference.com, dated 2024.06.10 β mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms