Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
BS::multi_future< T > Class Template Reference

A helper class to facilitate waiting for and/or getting the results of multiple futures at once. More...

#include <BS_thread_pool.hpp>

Inheritance diagram for BS::multi_future< T >:
Collaboration diagram for BS::multi_future< T >:

Public Member Functions

std::conditional_t< std::is_void_v< T >, void, std::vector< T > > get ()
 Get the results from all the futures stored in this BS::multi_future, rethrowing any stored exceptions.
 
std::size_t ready_count () const
 Check how many of the futures stored in this BS::multi_future are ready.
 
bool valid () const noexcept
 Check if all the futures stored in this BS::multi_future are valid.
 
void wait () const
 Wait for all the futures stored in this BS::multi_future.
 
template<typename R , typename P >
bool wait_for (const std::chrono::duration< R, P > &duration) const
 Wait for all the futures stored in this BS::multi_future, but stop waiting after the specified duration has passed. This function first waits for the first future for the desired duration. If that future is ready before the duration expires, this function waits for the second future for whatever remains of the duration. It continues similarly until the duration expires.
 
template<typename C , typename D >
bool wait_until (const std::chrono::time_point< C, D > &timeout_time) const
 Wait for all the futures stored in this BS::multi_future, but stop waiting after the specified time point has been reached. This function first waits for the first future until the desired time point. If that future is ready before the time point is reached, this function waits for the second future until the desired time point. It continues similarly until the time point is reached.
 

Detailed Description

template<typename T>
class BS::multi_future< T >

A helper class to facilitate waiting for and/or getting the results of multiple futures at once.

Template Parameters
TThe return type of the futures.

Member Function Documentation

◆ get()

template<typename T >
std::conditional_t< std::is_void_v< T >, void, std::vector< T > > BS::multi_future< T >::get ( )
inline

Get the results from all the futures stored in this BS::multi_future, rethrowing any stored exceptions.

Returns
If the futures return void, this function returns void as well. Otherwise, it returns a vector containing the results.
471 {
472 if constexpr (std::is_void_v<T>)
473 {
474 for (std::future<T>& future : *this)
475 future.get();
476 return;
477 }
478 else
479 {
480 std::vector<T> results;
481 results.reserve(this->size());
482 for (std::future<T>& future : *this)
483 results.push_back(future.get());
484 return results;
485 }
486 }
std::conditional_t< std::is_void_v< T >, void, std::vector< T > > get()
Get the results from all the futures stored in this BS::multi_future, rethrowing any stored exception...
Definition BS_thread_pool.hpp:470
GOpaque< Size > size(const GMat &src)
Here is the call graph for this function:

◆ ready_count()

template<typename T >
std::size_t BS::multi_future< T >::ready_count ( ) const
inline

Check how many of the futures stored in this BS::multi_future are ready.

Returns
The number of ready futures.
494 {
495 std::size_t count = 0;
496 for (const std::future<T>& future : *this)
497 {
498 if (future.wait_for(std::chrono::duration<double>::zero()) == std::future_status::ready)
499 ++count;
500 }
501 return count;
502 }

◆ valid()

template<typename T >
bool BS::multi_future< T >::valid ( ) const
inlinenoexcept

Check if all the futures stored in this BS::multi_future are valid.

Returns
true if all futures are valid, false if at least one of the futures is not valid.
510 {
511 bool is_valid = true;
512 for (const std::future<T>& future : *this)
513 is_valid = is_valid && future.valid();
514 return is_valid;
515 }
bool valid() const noexcept
Check if all the futures stored in this BS::multi_future are valid.
Definition BS_thread_pool.hpp:509

◆ wait()

template<typename T >
void BS::multi_future< T >::wait ( ) const
inline

Wait for all the futures stored in this BS::multi_future.

521 {
522 for (const std::future<T>& future : *this)
523 future.wait();
524 }
void wait() const
Wait for all the futures stored in this BS::multi_future.
Definition BS_thread_pool.hpp:520

◆ wait_for()

template<typename T >
template<typename R , typename P >
bool BS::multi_future< T >::wait_for ( const std::chrono::duration< R, P > &  duration) const
inline

Wait for all the futures stored in this BS::multi_future, but stop waiting after the specified duration has passed. This function first waits for the first future for the desired duration. If that future is ready before the duration expires, this function waits for the second future for whatever remains of the duration. It continues similarly until the duration expires.

Template Parameters
RAn arithmetic type representing the number of ticks to wait.
PAn std::ratio representing the length of each tick in seconds.
Parameters
durationThe amount of time to wait.
Returns
true if all futures have been waited for before the duration expired, false otherwise.
536 {
537 const std::chrono::time_point<std::chrono::steady_clock> start_time = std::chrono::steady_clock::now();
538 for (const std::future<T>& future : *this)
539 {
540 future.wait_for(duration - (std::chrono::steady_clock::now() - start_time));
541 if (duration < std::chrono::steady_clock::now() - start_time)
542 return false;
543 }
544 return true;
545 }

◆ wait_until()

template<typename T >
template<typename C , typename D >
bool BS::multi_future< T >::wait_until ( const std::chrono::time_point< C, D > &  timeout_time) const
inline

Wait for all the futures stored in this BS::multi_future, but stop waiting after the specified time point has been reached. This function first waits for the first future until the desired time point. If that future is ready before the time point is reached, this function waits for the second future until the desired time point. It continues similarly until the time point is reached.

Template Parameters
CThe type of the clock used to measure time.
DAn std::chrono::duration type used to indicate the time point.
Parameters
timeout_timeThe time point at which to stop waiting.
Returns
true if all futures have been waited for before the time point was reached, false otherwise.
557 {
558 for (const std::future<T>& future : *this)
559 {
560 future.wait_until(timeout_time);
561 if (timeout_time < C::now())
562 return false;
563 }
564 return true;
565 }

The documentation for this class was generated from the following file: