Dobiasd / FunctionalPlus

Functional Programming Library for C++. Write concise and readable C++ code.
http://www.editgym.com/fplus-api-search/
Boost Software License 1.0
2.07k stars 168 forks source link

add foreach, foreach_parallel and foreach_parallel_n_threads (fix #260) #261

Closed pthom closed 2 years ago

pthom commented 2 years ago

See https://github.com/Dobiasd/FunctionalPlus/issues/260

Example usage:

 constexpr int rows = 3000, cols = 2000;
 MandelbrotMat<rows, cols> mandelbrot_mat;
 auto fill_mandelbrot_row = [& mandelbrot_mat ](int row_idx) {
        ...
 };
 mandelbrot_mat = MandelbrotMat<rows, cols>();
 auto rows_idxs = fplus::numbers(0, rows);
 fplus::parallel_for(fill_mandelbrot_row, rows_idxs);
pthom commented 2 years ago

Yes to all your comments !

So, I changed the names to for_each, for_each_parallel and for_each_parallel_n_threads.

I removed the example from the API doc, as I 'm not sure it was that interesting.

Dobiasd commented 2 years ago

Thanks, looks good to me now. :+1:

(Since the example is now in the commit message, it won't be lost completely. ^^)

The original test was also interesting (at least to me), but the new one feels more standard, simpler, and boring. Boring code is good code. :grin: