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::task_and_future< R > Struct Template Reference

A class that takes a function with a return value (but no arguments), and constructs a task with no return value along with a future used to retrieve the function's return value once the task is executed. Used by submit_task() and submit_bulk(). More...

#include <BS_thread_pool.hpp>

Collaboration diagram for BS::task_and_future< R >:

Public Member Functions

template<typename F , typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, task_and_future<R>>>>
 task_and_future (F &&func)
 

Public Attributes

std::future< R > future
 
task_t task
 

Detailed Description

template<typename R>
struct BS::task_and_future< R >

A class that takes a function with a return value (but no arguments), and constructs a task with no return value along with a future used to retrieve the function's return value once the task is executed. Used by submit_task() and submit_bulk().

Template Parameters
RThe return type of the function (can be void).

Constructor & Destructor Documentation

◆ task_and_future()

template<typename R >
template<typename F , typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, task_and_future<R>>>>
BS::task_and_future< R >::task_and_future ( F &&  func)
inlineexplicit
732 {
733 std::promise<R> promise;
734 future = promise.get_future();
735 task = [task = std::forward<F>(func), promise = std::move(promise)]() mutable
736 {
737#ifdef __cpp_exceptions
738 try
739 {
740#endif
741 if constexpr (std::is_void_v<R>)
742 {
743 task();
744 promise.set_value();
745 }
746 else
747 {
748 promise.set_value(task());
749 }
750#ifdef __cpp_exceptions
751 }
752 catch (...)
753 {
754 try
755 {
756 promise.set_exception(std::current_exception());
757 }
758 catch (...)
759 {
760 }
761 }
762#endif
763 };
764 }

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