5#include <fmt/ostream.h>
32template <
class InputIt1,
class InputIt2,
class OutputIt>
34 InputIt2 first2, InputIt2 last2, OutputIt d_first)
36 while (first1 != last1 && first2 != last2) {
37 if (*first1 < *first2) {
40 if (!(*first2 < *first1)) {
41 *d_first++ = std::distance(ref1, first1++);
49template <
typename... Elements>
50auto make_array(Elements &&...elements) -> std::array<
typename std::common_type<Elements...>::type,
sizeof...(Elements)>
52 return {std::forward<Elements>(elements)...};
62template <
typename Container,
typename BinaryPredicate = std::equal_to<
typename Container::value_type>>
66 auto cbegin = c.begin();
72 auto cstart = cbegin + 1;
73 for (; cstart < cend; ++cbegin, ++cstart) {
74 if (std::find_if(cstart, cend,
75 [&p, cbegin](
const typename Container::value_type &v) ->
bool {
91template <
class InputIter,
class ElementType>
92void intersperse(InputIter first, InputIter last,
const ElementType &elem, std::ostream &out)
98 for (; first != last; ++first) {
99 out << elem << *first;
106template <
class InputIt1,
class InputIt2>
107std::pair<InputIt1, InputIt2>
108mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
110 while (first1 != last1 && first2 != last2 && *first1 == *first2) {
113 return std::make_pair(first1, first2);
117template <
typename InputIter>
119 using Size =
typename std::iterator_traits<InputIter>::difference_type;
130 out <<
"<Empty Range>";
139 auto dist = std::distance(
begin,
end);
140 const std::string sep{
", "};
145 std::advance(last1,
n);
147 out << sep <<
"... " << sep;
149 std::advance(first2, dist -
n);
154 auto mm = std::minmax_element(
begin,
end);
155 out <<
"] min:" << *mm.first <<
" max:" << *mm.second;
160template <
typename Iter>
171template <typename Range, typename Iter = typename Range::const_iterator, typename Size = typename std::iterator_traits<Iter>::difference_type>
174 return {n, std::begin(range), std::end(range)};
178template <
typename T,
typename Index,
size_t n>
179auto reorder_array(
const std::array<Index, n> &order,
const std::array<T, n> &elements) -> std::array<T, n>
181 static_assert(n > 0,
"Reordering nothing is pointless");
182 std::array<T, n> reordered;
183 for (std::size_t i = 0; i < n; ++i) {
184 reordered[i] = elements[order[i]];
189template <
class InputIt,
class Size,
class InOutIt>
190void add_n(InputIt first, Size count, InOutIt result)
192 std::transform(first, std::next(first, count), result, result, std::plus{});
196template <
class InputIt,
class Unary>
199 using Inner = std::remove_cv_t<std::remove_reference_t<
decltype(*first)>>;
200 std::set<Inner> seen;
201 std::for_each(first, last, [&seen, &func](
const auto &elem) {
202 if (seen.count(elem) == 0) {
210template <
class InputIt,
class Predicate>
213 auto firstMatch = std::find_if(first, last, p);
214 if (firstMatch == last) {
217 auto trailing = firstMatch;
218 auto next = std::next(firstMatch);
219 while (next != last && p(*next)) {
223 return {firstMatch, trailing};
228template <
typename Iter>
229struct fmt::formatter<
precice::utils::RangePreview<Iter>> : ostream_formatter {
contains precice-related utilities.
auto reorder_array(const std::array< Index, n > &order, const std::array< T, n > &elements) -> std::array< T, n >
Reorders an array given an array of unique indices.
void add_n(InputIt first, Size count, InOutIt result)
void for_each_unique(InputIt first, InputIt last, Unary func)
Calls each value in the range of [first, last[ exactly once.
std::pair< InputIt, InputIt > find_first_range(InputIt first, InputIt last, Predicate p)
Finds the first range in [first, last[ that fulfills a predicate.
void intersperse(InputIter first, InputIter last, const ElementType &elem, std::ostream &out)
const RangePreview< Iter > previewRange(Size n, const Range &range)
bool unique_elements(const Container &c, BinaryPredicate p={})
std::ostream & operator<<(std::ostream &out, const RangePreview< Iter > &rp)
Allows streaming of RangePreview objects.
auto make_array(Elements &&...elements) -> std::array< typename std::common_type< Elements... >::type, sizeof...(Elements)>
Function that generates an array from given elements.
void set_intersection_indices(InputIt1 ref1, InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first)
This function is by and large the same as std::set_intersection(). The only difference is that we don...
std::pair< InputIt1, InputIt2 > mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
Main namespace of the precice library.
The RangePreview object used as a lazy proxy struct for proviewing the content of a Range.
typename std::iterator_traits< InputIter >::difference_type Size
RangePreview(Size n, InputIter begin, InputIter end)
void print(std::ostream &out) const