Parallelizing your own algorithm within the MPTL

// Parallel Algorithm Interface for std::generate
template <typename Iterator, typename Generator>
class MPTLGenerate
{
private:
    Iterator first1, last1;  // global, serial range
    Generator gen;           // generator function object
 
public:
    typedef Iterator iterator1;       // type of the iterators
    typedef TwoIterators nIterators;  // two iterators are parallelized
 
    MPTLGenerate(Iterator first1_, Iterator last1_, Generator gen_)
        : first1(first1_), last1(last1_), gen(gen_) { }
 
    // getter methods for the global iterators
    Iterator getFirst1() { return first1; }
    Iterator getLast1() { return last1; }
 
    // apply the algorithm to a subrange
    void applyAlgorithm(Iterator first, Iterator last) {
        std::generate(first, last, gen);
    }
};
 
// Convenience function that constructs a MPTLGenerate object
template <typename Iterator, typename Generator>
MPTLGenerate<Iterator, Generator> generate(Iterator first, Iterator last,
                                           Generator gen)
{
    return MPTLGenerate<Iterator, Generator>(first, last, gen);
}