Skip to content
Snippets Groups Projects

cleanup for petscsolver

Merged Praetorius, Simon requested to merge issue/cleanup_for_petscsolver into master
Files
7
#pragma once
#include <algorithm>
#include <functional>
#include <utility>
namespace AMDiS
{
template <class InputIter, class T, class Func>
void split(InputIter first, InputIter end, T const& t, Func f)
/// \brief Split a sequence `[first,last)` by the separators `sep` and pass the tokens as
/// begin-end iterator pair to the provided functor `f = void(InputIterator, InputIterator)`
template <class InputIter, class Tp, class BinaryFunc>
void split(InputIter first, InputIter last, Tp sep, BinaryFunc f)
{
if (first == end)
if (first == last)
return;
while (true) {
InputIter found = std::find(first, end, t);
InputIter found = std::find(first, last, sep);
f(first, found);
if (found == end)
if (found == last)
break;
first = ++found;
}
}
template <class InputIter, class SeparaterIter, class Func>
void split(InputIter first, InputIter end, SeparaterIter s_first, SeparaterIter s_end, Func f)
/// \brief Split a sequence `[first,last)` by any of the separators `[s_first, s_last)` and pass the tokens as
/// begin-end iterator pair to the provided functor `f = void(InputIterator, InputIterator)`
template <class InputIter, class SeparaterIter, class BinaryFunc>
void split(InputIter first, InputIter last, SeparaterIter s_first, SeparaterIter s_last, BinaryFunc f)
{
if (first == end)
if (first == last)
return;
while (true) {
InputIter found = std::find_first_of(first, end, s_first, s_end);
InputIter found = std::find_first_of(first, last, s_first, s_last);
f(first, found);
if (found == end)
if (found == last)
break;
first = ++found;
}
}
/// \brief Output the cumulative sum of one range to a second range
// NOTE: backport of std::exclusive_scan from c++17
template <class InputIter, class OutputIter, class Tp, class BinaryOperation>
OutputIter exclusive_scan(InputIter first, InputIter last,
OutputIter result, Tp init, BinaryOperation binary_op)
{
while (first != last) {
auto v = init;
init = binary_op(init, *first);
++first;
*result++ = std::move(v);
}
return result;
}
/// \brief Output the cumulative sum of one range to a second range
// NOTE: backport of std::exclusive_scan from c++17
template <class InputIter, class OutputIter, class Tp>
inline OutputIter exclusive_scan(InputIter first, InputIter last,
OutputIter result, Tp init)
{
return AMDiS::exclusive_scan(first, last, result, std::move(init), std::plus<>());
}
}
\ No newline at end of file
Loading