HPX - High Performance ParalleX


Function template generate_n



// In header: <hpx/parallel/algorithms/generate.hpp>

template<typename ExPolicy, typename OutIter, typename Size, typename F> 
  unspecified generate_n(ExPolicy && policy, OutIter first, Size count, 
                         F && f);


Assigns each element in range [first, first+count) a value generated by the given function object g.

[Note] Note

Complexity: Exactly count invocations of f and assignments, for count > 0.

The assignments in the parallel generate_n algorithm invoked with an execution policy object of type sequential_execution_policy execute in sequential order in the calling thread.

The assignments in the parallel generate_n algorithm invoked with an execution policy object of type parallel_execution_policy or parallel_task_execution_policy are permitted to execute in an unordered fashion in unspecified threads, and indeterminately sequenced within each thread.



Refers to the number of elements in the sequence the algorithm will be applied to.


Refers to the generator function object that will be called. The signature of the function should be equivalent to

Ret fun();

The type Ret must be such that an object of type OutputIt can be dereferenced and assigned a value of type Ret.


Refers to the beginning of the sequence of elements the algorithm will be applied to.


The execution policy to use for the scheduling of the iterations.

Template Parameters:


The type of the execution policy to use (deduced). It describes the manner in which the execution of the algorithm may be parallelized and the manner in which it executes the assignments.


The type of the function/function object to use (deduced). Unlike its sequential form, the parallel overload of equal requires F to meet the requirements of CopyConstructible.


The type of the source iterators used (deduced). This iterator type must meet the requirements of an output iterator.


The replace_if algorithm returns a hpx::future<void> if the execution policy is of type sequential_task_execution_policy or parallel_task_execution_policy and returns void otherwise.