5#include <fmt/ostream.h>
33template <
class InputIt1,
class InputIt2,
class OutputIt>
35 InputIt2 first2, InputIt2 last2, OutputIt d_first)
37 while (first1 != last1 && first2 != last2) {
38 if (*first1 < *first2) {
41 if (!(*first2 < *first1)) {
50template <
typename... Elements>
53 return {std::forward<Elements>(elements)...};
63template <
typename Container,
typename BinaryPredicate = std::equal_to<
typename Container::value_type>>
67 auto cbegin = c.begin();
73 auto cstart = cbegin + 1;
74 for (; cstart < cend; ++cbegin, ++cstart) {
76 [&p, cbegin](
const typename Container::value_type &v) ->
bool {
92template <
class InputIter,
class ElementType>
99 for (; first != last; ++first) {
100 out << elem << *first;
107template <
class InputIt1,
class InputIt2>
109mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
111 while (first1 != last1 && first2 != last2 && *first1 == *first2) {
118template <
typename InputIter>
131 out <<
"<Empty Range>";
148 out << sep <<
"... " << sep;
156 out <<
"] min:" << *mm.first <<
" max:" << *mm.second;
161template <
typename Iter>
172template <typename Range, typename Iter = typename Range::const_iterator, typename Size = typename std::iterator_traits<Iter>::difference_type>
179template <
typename T,
typename Index,
size_t n>
182 static_assert(n > 0,
"Reodering nothing is pointless");
185 reordered[i] = elements[order[i]];
190template <
class InputIt,
class Size,
class InOutIt>
191void add_n(InputIt first, Size count, InOutIt result)
197template <
class InputIt,
class Unary>
202 std::for_each(first, last, [&seen, &func](
const auto &elem) {
203 if (seen.
count(elem) == 0) {
211template <
class InputIt,
class Predicate>
215 if (firstMatch == last) {
218 auto trailing = firstMatch;
220 while (next != last && p(*next)) {
224 return {firstMatch, trailing};
230template <
typename Iter>
231struct fmt::formatter<
precice::utils::RangePreview<Iter>> : ostream_formatter {
T minmax_element(T... args)
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.
auto make_array(Elements &&... elements) -> std::array< typename std::common_type< Elements... >::type, sizeof...(Elements)>
Function that generates an array from given elements.
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.
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