20#ifndef CORE_UTILS_FOR_EACH_PAIR_HPP
21#define CORE_UTILS_FOR_EACH_PAIR_HPP
34template <
typename ForwardIterator,
typename BinaryOp>
35void for_each_pair(ForwardIterator first, ForwardIterator last, BinaryOp op) {
36 while (first != last) {
37 for (
auto it = std::next(first); it != last; ++it) {
46template <
typename ForwardRange,
typename BinaryOp>
50 for_each_pair(begin(rng), end(rng), std::forward<BinaryOp>(op));
61template <
typename ForwardIterator,
typename BinaryOp>
63 ForwardIterator first2, ForwardIterator last2,
65 while (first1 != last1) {
66 for (
auto it = first2; it != last2; ++it) {
75template <
typename ForwardRange,
typename BinaryOp>
81 std::forward<BinaryOp>(op));
92template <
typename ForwardIterator,
typename BinaryOp,
typename BinaryCmp>
94 ForwardIterator first2, ForwardIterator last2,
95 BinaryOp op, BinaryCmp cmp) {
96 while (first1 != last1) {
97 for (
auto it = first2; it != last2; ++it) {
98 if (cmp(*first1, *it)) {
108template <
typename ForwardRange,
typename BinaryOp,
typename BinaryCmp>
110 BinaryOp &&op, BinaryCmp cmp) {
114 std::forward<BinaryOp>(op),
115 std::forward<BinaryCmp>(cmp));
void for_each_pair(ForwardIterator first, ForwardIterator last, BinaryOp op)
Execute op for each pair of elements in [first, last) once.
void for_each_cartesian_pair(ForwardIterator first1, ForwardIterator last1, ForwardIterator first2, ForwardIterator last2, BinaryOp op)
Execute op for each pair of elements between [first1, last1) and [first2, last2).
void for_each_cartesian_pair_if(ForwardIterator first1, ForwardIterator last1, ForwardIterator first2, ForwardIterator last2, BinaryOp op, BinaryCmp cmp)
Execute op for each pair of elements between [first1, last1) and [first2, last2) if a condition is sa...