close
Namespaces
Variants

Template talk:par pred2

From cppreference.com

(thus, Type1 & is not allowed, nor is Type1 unless for Type1 a move is equivalent to a copy (since C++11)

Shouldn't it be Type1&&?

The stuff about references non-sense, pay no attention to it. The actual requirement is that the expression bool(pred(*first1, *first2)) or bool(pred(*first, value)) is well formed and that pred doesn't apply a non-const function on any of the dereferenced iterators (a move that isn't a copy for example). So, for example, all of the following are fine:
#include <array>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <iterator>

int main()
{
    std::array x{1, 2, 3}, y{1, 2, 3};
    std::move_iterator
        moveIt_x_begin(begin(x)),
        moveIt_x_end(end(x)),
        moveIt_y_begin(begin(y));

    bool value(std::equal(begin(x), end(x), begin(y), [](int lhs, int rhs)
    {
        return lhs == rhs;
    }));
    bool lref(std::equal(begin(x), end(x), begin(y), [](int& lhs, int& rhs)
    {
        return lhs == rhs;
    }));
    bool lref_const(std::equal(begin(x), end(x), begin(y), [](const int& lhs, const int& rhs)
    {
        return lhs == rhs;
    }));
    bool rref(std::equal(moveIt_x_begin, moveIt_x_end, moveIt_y_begin, [](int&& lhs, int&& rhs)
    {
        return lhs == rhs;
    }));
    bool rref_const(std::equal(moveIt_x_begin, moveIt_x_end, moveIt_y_begin, [](const int&& lhs, const int&& rhs)
    {
        return lhs == rhs;
    }));
    
    std::cout
        << std::boolalpha
        << value << '\n'
        << lref << '\n'
        << lref_const << '\n'
        << rref << '\n'
        << rref_const << '\n';
}

Output:

true
true
true
true
true
--Ybab321 (talk) 08:08, 11 April 2023 (PDT)