7 #include <execution/Executor.h> 
   30             template <
class F, 
class TArg>
 
   32                                 std::exception_ptr& except, F&& f )
 
   34                 static_assert( std::is_invocable<F, TArg>::value,
 
   35                                "inlineExecutor::_invokeInline bad signature" );
 
   36                 if constexpr ( std::is_nothrow_invocable<F, TArg>::value )
 
   49                             except = std::current_exception();
 
   56                                 std::exception_ptr& except, F&& f )
 
   59                 if constexpr ( std::is_nothrow_invocable<F>::value )
 
   72                             except = std::current_exception();
 
   76             template <
class TArg, 
class F, 
class... FTypes>
 
   78                                 std::exception_ptr& except, F&& f,
 
   81                 _invokeInline( fut, except, std::forward<F>( f ) );
 
   82                 _invokeInline( fut, except, std::forward<FTypes>( fs )... );
 
   84             template <
int n, 
class ResultTuple, 
class F, 
class TArg>
 
   87                                        std::exception_ptr& except,
 
   88                                        ResultTuple& output, F&& f )
 
   91                     std::is_invocable<F, TArg>::value,
 
   92                     "inlineExecutor::_invokeInline_with_result bad signature" );
 
   93                 if constexpr ( std::is_nothrow_invocable<F, TArg>::value )
 
   95                     if constexpr ( std::is_same<std::invoke_result_t<F, TArg>,
 
   99                         std::get<n>( output ) = f( fut.
getValue().value() );
 
  105                         if constexpr ( std::is_same<
 
  106                                            std::invoke_result_t<F, TArg>,
 
  110                             std::get<n>( output ) = f( fut.
getValue().value() );
 
  115                             except = std::current_exception();
 
  120             template <
int n, 
class ResultTuple, 
class F>
 
  121             void _invokeInline_with_result(
 
  123                 std::exception_ptr& except, ResultTuple& output, F&& f )
 
  125                 if constexpr ( std::is_nothrow_invocable<F>::value )
 
  127                     if constexpr ( std::is_same<std::invoke_result_t<F>,
 
  131                         std::get<n>( output ) = f();
 
  137                         if constexpr ( std::is_same<std::invoke_result_t<F>,
 
  141                             std::get<n>( output ) = f();
 
  146                             except = std::current_exception();
 
  151             template <
int n, 
class ResultTuple, 
class TArg, 
class F,
 
  155                                        std::exception_ptr& except,
 
  156                                        ResultTuple& output, F&& f,
 
  159                 _invokeInline_with_result<n>( fut, except, output,
 
  160                                               std::forward<F>( f ) );
 
  161                 _invokeInline_with_result<n + 1>(
 
  162                     fut, except, output, std::forward<FTypes>( fs )... );
 
  167         template <
class TArg, 
class I, 
class F>
 
  170               F&& functor, 
int increment = 1 )
 
  172             if ( source.getValid() )
 
  174                 std::exception_ptr except{ 
nullptr };
 
  175                 auto& v = source.
getValue().value();
 
  176                 auto iterators = getIteratorsFunc( v );
 
  177                 using IteratorType = decltype( iterators[0] );
 
  178                 static_assert( std::is_invocable<F, IteratorType, TArg>::value,
 
  179                                "InlineExecutor::loop bad signature" );
 
  182                 if constexpr ( std::is_nothrow_invocable<F, IteratorType,
 
  185                     for ( 
auto i = iterators[0]; i != iterators[1];
 
  193                     for ( 
auto i = iterators[0]; i != iterators[1];
 
  203                                 except = std::current_exception();
 
  214                     result.setError( except );
 
  222                 result.setError( source.
getValue().error() );
 
  227         template <
class I, 
class F>
 
  230               F&& functor, 
int increment = 1 )
 
  232             if ( source.getValid() )
 
  234                 std::exception_ptr except{ 
nullptr };
 
  235                 auto iterators = getIteratorsFunc();
 
  236                 using IteratorType = decltype( iterators[0] );
 
  237                 if constexpr ( std::is_nothrow_invocable<F,
 
  238                                                          IteratorType>::value )
 
  240                     for ( 
auto i = iterators[0]; i != iterators[1];
 
  248                     for ( 
auto i = iterators[0]; i != iterators[1];
 
  258                                 except = std::current_exception();
 
  269                     result.setError( except );
 
  277                 result.setError( source.
getValue().error() );
 
  281         template <
class TArg, 
class... FTypes>
 
  284                   FTypes&&... functions )
 
  286             std::exception_ptr except{ 
nullptr };
 
  287             if ( source.getValid() )
 
  289                 _private::_invokeInline( source, except,
 
  290                                          std::forward<FTypes>( functions )... );
 
  298                     result.setError( except );
 
  306                 result.setError( source.
getValue().error() );
 
  339         template <
class TArg, 
class... FTypes>
 
  342             typename mel::execution::_private::GetReturn<TArg, FTypes...>::type>
 
  344                           FTypes&&... functions )
 
  346             typedef typename mel::execution::_private::GetReturn<
 
  347                 TArg, FTypes...>::type ResultTuple;
 
  348             std::exception_ptr except{ 
nullptr };
 
  349             if ( source.getValid() )
 
  353                 ResultTuple resultTuple;
 
  354                 _private::_invokeInline_with_result<0>(
 
  355                     source, except, resultTuple,
 
  356                     std::forward<FTypes>( functions )... );
 
  358                     result.setValue( std::move( resultTuple ) );
 
  361                     result.setError( except );
 
  369                 result.setError( source.
getValue().error() );
 
  382             typedef std::invoke_result_t<F> TRet;
 
  384             if constexpr ( std::is_same<TRet, void>::value )
 
  386                 if constexpr ( std::is_nothrow_invocable<F>::value )
 
  402                         result.setError( std::current_exception() );
 
  409                 if constexpr ( std::is_nothrow_invocable<F>::value )
 
  421                         result.setError( std::current_exception() );
 
  432         template <
class TArg, 
class F>
 
  444             static_assert( std::is_invocable<F, TArg>::value,
 
  445                            "InlineExecutor::launch. Bad signature" );
 
  446             typedef std::invoke_result_t<F, TArg> TRet;
 
  449             if constexpr ( std::is_same<TRet, void>::value )
 
  451                 if constexpr ( std::is_nothrow_invocable<F, TArg>::value )
 
  453                     f( std::forward<TArg>( arg ) );
 
  460                         f( std::forward<TArg>( arg ) );
 
  467                         result.setError( std::current_exception() );
 
  474                 if constexpr ( std::is_nothrow_invocable<F, TArg>::value )
 
  476                         ex, f( std::forward<TArg>( arg ) ) );
 
  482                             ex, f( std::forward<TArg>( arg ) ) );
 
  488                         result.setError( std::current_exception() );
 
  497         template <
class F, 
class TArg>
 
  501             static_assert( std::is_invocable<F, TArg>::value,
 
  502                            "InlineExecutor::next. Bad signature" );
 
  503             typedef std::invoke_result_t<F, TArg> TRet;
 
  504             if ( source.getValid() )
 
  506                 if constexpr ( std::is_same<TRet, void>::value )
 
  508                     if constexpr ( std::is_nothrow_invocable<F, TArg>::value )
 
  527                             result.setError( std::current_exception() );
 
  534                     if constexpr ( std::is_nothrow_invocable<F, TArg>::value )
 
  551                             result.setError( std::current_exception() );
 
  563                 result.setError( source.
getValue().error() );
 
  572             typedef std::invoke_result_t<F> TRet;
 
  573             if ( source.getValid() )
 
  575                 if constexpr ( std::is_same<TRet, void>::value )
 
  577                     if constexpr ( std::is_nothrow_invocable<F>::value )
 
  596                             result.setError( std::current_exception() );
 
  603                     if constexpr ( std::is_nothrow_invocable<F>::value )
 
  620                             result.setError( std::current_exception() );
 
  632                 result.setError( source.
getValue().error() );
 
  638         template <
class TArg, 
class TRet>
 
  640                  typename std::remove_cv<
 
  641                      typename std::remove_reference<TRet>::type>::type>
 
  645                 !std::is_lvalue_reference<TRet>::value ||
 
  647                         typename std::remove_reference<TRet>::type>::value,
 
  648                 "execution::inmediate. Use std::ref() to pass argument as " 
  650             using NewType = 
typename std::remove_cv<
 
  651                 typename std::remove_reference<TRet>::type>::type;
 
  653                 fut.
agent, std::forward<TRet>( arg ) );
 
Typical Traits for types.
 
const _private::FutureData< T >::ValueType & getValue() const
Get the Value object.
Definition: Future.h:613
 
Extension of mel::core::Future to apply to executors.
Definition: ExFuture.h:21
 
Executor< ExecutorAgent > agent
execution agent associated with this instance
Definition: ExFuture.h:54
 
Executor specialization using InlineExecutionAgent as execution agent.
Definition: InlineExecutor.h:26
 
Definition: Executor.h:26
 
High level execution utilities.
Definition: CommonDefs.h:10
 
ExFuture< ExecutorAgent, typename std::remove_cv< typename std::remove_reference< TRet >::type >::type > inmediate(ExFuture< ExecutorAgent, TArg > fut, TRet &&arg)
Produces an inmediate value in the context of the given ExFuture executor as a response to input fut ...
Definition: Executor.h:117
 
ExFuture< ExecutorAgent, std::invoke_result_t< F > > launch(Executor< ExecutorAgent > ex, F &&f)
Launch given functor in given executor.
Definition: Executor.h:65
 
ExFuture< ExecutorAgent, TArg > parallel(ExFuture< ExecutorAgent, TArg > source, FTypes... functions)
Execute given functions in a (possibly, depending on concrete executor) parallel way If an exception ...
Definition: Executor.h:499
 
ExFuture< ExecutorAgent, TArg > loop(ExFuture< ExecutorAgent, TArg > source, I getIteratorsFunc, F functor, int increment=1)
parallel (possibly, depending on executor capabilities) loop
Definition: Executor.h:290
 
ExFuture< ExecutorAgent, typename ::mel::execution::_private::GetReturn< TArg, FTypes... >::type > parallel_convert(ExFuture< ExecutorAgent, TArg > source, FTypes... functions)
Same as parallel but returning a tuple with the values for each functor.
Definition: Executor.h:726
 
ExFuture< ExecutorAgent, std::invoke_result_t< F, TArg > > next(ExFuture< ExecutorAgent, TArg > source, F f)
Attach a functor to execute when input fut is complete Given functor will be executed inf the input E...
Definition: Executor.h:166
 
Executor< InlineExecutionAgent > InlineExecutor
alias for Executor<InlineExecutionAgent>
Definition: InlineExecutor.h:665
 
Definition: Callback_Impl.h:11
 
Default traits for any executor.
Definition: Executor.h:46
 
Definition: InlineExecutor.h:17