std::equal
Актуально для C++23.
#include <algorithm>
Актуально на 2024-02-29.
Define overload #1
template<class InputIt1, class InputIt2> constexpr inline bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2);
Сравнивает диапазон [first1, last1] с диапазоном [first2, first2 + std::distance(first1, last1)] на идентичность.
Для сравнения используется оператор ==.
Вернёт true если они эквивалентны, иначе - false.
Example, possible implementation
Define overload #2
template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> bool equal(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
Example, possible implementation
Define overload #3
template<class InputIt1, class InputIt2, class BinaryPredicate> constexpr inline bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryPredicate pred)
Сравнивает диапазон [first1, last1] с диапазоном [first2, first2 + std::distance(first1, last1)] на идентичность.
Для сравнения используется бинарный предикат "pred".
Вернёт true если они эквивалентны, иначе - false.
Example, possible implementation
Define overload #4
template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> bool equal(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate p);
Example, possible implementation
Define overload #5
template<class InputIt1, class InputIt2> constexpr inline bool equal(class InputIt1 first1, class InputIt1 last1, InputIt2 first2, InputIt2 last2)
Сравнивает диапазон [first1, last1] с диапазоном [first2, last2] на идентичность.
Для сравнения используется оператор ==.
Вернёт true если они эквивалентны, иначе - false.
Example, possible implementation
Define overload #6
template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> bool equal(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);
Example, possible implementation
Define overload #7
template<class InputIt1, class InputIt2, class BinaryPredicate> constexpr inline bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryPredicate pred)
Сравнивает диапазон [first1, last1] с диапазоном [first2, last2] на идентичность.
Для сравнения используется бинарный предикат "pred".
Вернёт true если они эквивалентны, иначе - false.
Example, possible implementation
Define overload #8
template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> bool equal(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate p);
Example, possible implementation
Examples
Example 1:
#include <iostream> #include <algorithm> #include <string> int main() { std::string str1{"aabccdedfff"}; std::string str2{"aabccdedfff"}; auto end = std::equal(std::begin(str1), std::end(str1), std::begin(str2)); if (end) { std::cout << "range is equivalent" << std::endl; } else { std::cout << "range is not equivalent" << std::endl; } return 0; }
range is equivalent
Example 2:
#include <iostream> #include <algorithm> #include <string> int main() { auto pred = [](auto a1, auto a2) { return a1 == a2; }; std::string str1{"aabccdedfff"}; std::string str2{"aabccdedff"}; auto end = std::equal(std::begin(str1), std::end(str1), std::begin(str2), pred); if (end) { std::cout << "range is equivalent" << std::endl; } else { std::cout << "range is not equivalent" << std::endl; } return 0; }
range is not equivalent
Changelog
C++26
TODOC++23
TODOC++20
TODOC++17
TODOC++14
TODOC++11
TODOSee also
TODO
This page was last modified on 2024-02-29