add mismatch algorithm: robust version (N3607)

This commit is contained in:
bolero-MURAKAMI 2013-05-16 15:13:49 +09:00
parent c71502f6b6
commit dce6fff6a4
4 changed files with 424 additions and 7 deletions

View file

@ -21,6 +21,7 @@ namespace testspr {
sprout::begin(arr2)
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1) + 7);
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2) + 7);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -29,6 +30,7 @@ namespace testspr {
sprout::begin(arr3)
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -37,6 +39,7 @@ namespace testspr {
sprout::begin(arr2)
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -45,6 +48,7 @@ namespace testspr {
sprout::begin(arr3)
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2));
}
{
@ -55,6 +59,7 @@ namespace testspr {
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1) + 7);
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2) + 7);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -64,6 +69,7 @@ namespace testspr {
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -73,6 +79,7 @@ namespace testspr {
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -82,6 +89,7 @@ namespace testspr {
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2));
}
{
@ -91,6 +99,7 @@ namespace testspr {
testspr::reduct_input(sprout::begin(arr2))
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 7);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 7);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -99,6 +108,7 @@ namespace testspr {
testspr::reduct_input(sprout::begin(arr3))
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -107,6 +117,7 @@ namespace testspr {
testspr::reduct_input(sprout::begin(arr2))
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -115,6 +126,7 @@ namespace testspr {
testspr::reduct_input(sprout::begin(arr3))
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
{
@ -125,6 +137,7 @@ namespace testspr {
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 7);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 7);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -134,6 +147,7 @@ namespace testspr {
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -143,6 +157,7 @@ namespace testspr {
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -152,6 +167,7 @@ namespace testspr {
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
#if defined(__clang__)
@ -162,6 +178,7 @@ namespace testspr {
testspr::reduct_random_access(sprout::begin(arr2))
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 7);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 7);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -170,6 +187,7 @@ namespace testspr {
testspr::reduct_random_access(sprout::begin(arr3))
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -178,6 +196,7 @@ namespace testspr {
testspr::reduct_random_access(sprout::begin(arr2))
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -186,6 +205,7 @@ namespace testspr {
testspr::reduct_random_access(sprout::begin(arr3))
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
{
@ -196,6 +216,7 @@ namespace testspr {
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 7);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 7);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -205,6 +226,7 @@ namespace testspr {
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -214,6 +236,7 @@ namespace testspr {
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
@ -223,6 +246,267 @@ namespace testspr {
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
#endif
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
sprout::begin(arr1),
sprout::end(arr1),
sprout::begin(arr2),
sprout::end(arr2)
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1) + 7);
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2) + 7);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
sprout::begin(arr1),
sprout::end(arr1),
sprout::begin(arr3),
sprout::end(arr2)
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
sprout::begin(arr1),
sprout::end(arr1),
sprout::begin(arr2),
sprout::begin(arr2) + 5
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
sprout::begin(arr1),
sprout::end(arr1),
sprout::begin(arr3),
sprout::begin(arr2) + 5
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
sprout::begin(arr1),
sprout::end(arr1),
sprout::begin(arr2),
sprout::end(arr2),
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1) + 7);
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2) + 7);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
sprout::begin(arr1),
sprout::end(arr1),
sprout::begin(arr3),
sprout::end(arr2),
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
sprout::begin(arr1),
sprout::end(arr1),
sprout::begin(arr2),
sprout::begin(arr2) + 5,
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
sprout::begin(arr1),
sprout::end(arr1),
sprout::begin(arr3),
sprout::begin(arr2) + 5,
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_input(sprout::begin(arr1)),
testspr::reduct_input(sprout::end(arr1)),
testspr::reduct_input(sprout::begin(arr2)),
testspr::reduct_input(sprout::end(arr2))
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 7);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 7);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_input(sprout::begin(arr1)),
testspr::reduct_input(sprout::end(arr1)),
testspr::reduct_input(sprout::begin(arr3)),
testspr::reduct_input(sprout::end(arr2))
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_input(sprout::begin(arr1)),
testspr::reduct_input(sprout::end(arr1)),
testspr::reduct_input(sprout::begin(arr2)),
testspr::reduct_input(sprout::begin(arr2) + 5)
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_input(sprout::begin(arr1)),
testspr::reduct_input(sprout::end(arr1)),
testspr::reduct_input(sprout::begin(arr3)),
testspr::reduct_input(sprout::begin(arr2) + 5)
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_input(sprout::begin(arr1)),
testspr::reduct_input(sprout::end(arr1)),
testspr::reduct_input(sprout::begin(arr2)),
testspr::reduct_input(sprout::end(arr2)),
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 7);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 7);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_input(sprout::begin(arr1)),
testspr::reduct_input(sprout::end(arr1)),
testspr::reduct_input(sprout::begin(arr3)),
testspr::reduct_input(sprout::end(arr2)),
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_input(sprout::begin(arr1)),
testspr::reduct_input(sprout::end(arr1)),
testspr::reduct_input(sprout::begin(arr2)),
testspr::reduct_input(sprout::begin(arr2) + 5),
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_input(sprout::begin(arr1)),
testspr::reduct_input(sprout::end(arr1)),
testspr::reduct_input(sprout::begin(arr3)),
testspr::reduct_input(sprout::begin(arr2) + 5),
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
#if defined(__clang__)
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::reduct_random_access(sprout::begin(arr2)),
testspr::reduct_random_access(sprout::end(arr2))
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 7);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 7);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::reduct_random_access(sprout::begin(arr3)),
testspr::reduct_random_access(sprout::end(arr2))
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::reduct_random_access(sprout::begin(arr2)),
testspr::reduct_random_access(sprout::begin(arr2) + 5)
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::reduct_random_access(sprout::begin(arr3)),
testspr::reduct_random_access(sprout::begin(arr2) + 5)
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::reduct_random_access(sprout::begin(arr2)),
testspr::reduct_random_access(sprout::end(arr2)),
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 7);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 7);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::reduct_random_access(sprout::begin(arr3)),
testspr::reduct_random_access(sprout::end(arr2)),
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::reduct_random_access(sprout::begin(arr2)),
testspr::reduct_random_access(sprout::begin(arr2) + 5),
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2) + 5);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::mismatch(
testspr::reduct_random_access(sprout::begin(arr1)),
testspr::reduct_random_access(sprout::end(arr1)),
testspr::reduct_random_access(sprout::begin(arr3)),
testspr::reduct_random_access(sprout::begin(arr2) + 5),
testspr::equal_to<int>()
);
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1));
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr2));
}
#endif
}

View file

@ -8,8 +8,8 @@
#include <sprout/iterator/type_traits/category.hpp>
#include <sprout/iterator/type_traits/common.hpp>
#include <sprout/utility/pair/pair.hpp>
#include <sprout/algorithm/min.hpp>
#include <sprout/functional/less.hpp>
#include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT
namespace sprout {
namespace detail {
@ -76,7 +76,7 @@ namespace sprout {
: first1 == last1 ? true
: sprout::detail::lexicographical_compare_impl_ra(
first1, last1, first2, last2, comp,
sprout::min(sprout::distance(first1, last1), sprout::distance(first2, last2))
NS_SSCRISK_CEL_OR_SPROUT::min(sprout::distance(first1, last1), sprout::distance(first2, last2))
)
;
}

View file

@ -10,16 +10,18 @@
#include <sprout/tuple/tuple/get.hpp>
#include <sprout/functional/equal_to.hpp>
#include <sprout/utility/pair/pair.hpp>
#include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT
namespace sprout {
namespace detail {
template<typename RandomAccessIterator1, typename RandomAccessIterator2>
inline SPROUT_CONSTEXPR sprout::pair<RandomAccessIterator1, RandomAccessIterator2>
mismatch_impl_ra_1(RandomAccessIterator1 first1, RandomAccessIterator2 first2, RandomAccessIterator1 found) {
mismatch_impl_check(RandomAccessIterator1 first1, RandomAccessIterator2 first2, RandomAccessIterator1 found) {
return sprout::pair<RandomAccessIterator1, RandomAccessIterator2>{
found, sprout::next(first2, sprout::distance(first1, found))
};
}
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR RandomAccessIterator1
mismatch_impl_ra(
@ -51,7 +53,7 @@ namespace sprout {
)
{
return first1 == last1 ? sprout::pair<RandomAccessIterator1, RandomAccessIterator2>{first1, first2}
: sprout::detail::mismatch_impl_ra_1(
: sprout::detail::mismatch_impl_check(
first1, first2,
sprout::detail::mismatch_impl_ra(
first1, last1, first2, pred,
@ -137,6 +139,137 @@ namespace sprout {
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2) {
return sprout::mismatch(first1, last1, first2, sprout::equal_to<>());
}
namespace detail {
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR RandomAccessIterator1
mismatch2_impl_ra_1(
RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, RandomAccessIterator2 last2, BinaryPredicate pred,
typename std::iterator_traits<RandomAccessIterator1>::difference_type pivot, RandomAccessIterator1 found
)
{
return found != first1 ? found
: pivot == 0 ? (!pred(*first1, *first2) ? first1 : last1)
: sprout::detail::mismatch2_impl_ra_1(
sprout::next(first1, pivot), last1, sprout::next(first2, pivot), last2, pred,
(sprout::distance(first1, last1) - pivot) / 2,
sprout::detail::mismatch2_impl_ra_1(
first1, sprout::next(first1, pivot), first2, sprout::next(first2, pivot), pred,
pivot / 2,
first1
)
)
;
}
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR RandomAccessIterator1
mismatch2_impl_ra(
RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, RandomAccessIterator2 last2, BinaryPredicate pred,
typename std::iterator_traits<RandomAccessIterator1>::difference_type size
)
{
return sprout::detail::mismatch2_impl_ra_1(
first1, sprout::next(first1, size), first2, sprout::next(first2, size), pred,
size / 2, first1
);
}
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::is_constant_distance_iterator<RandomAccessIterator1>::value && sprout::is_constant_distance_iterator<RandomAccessIterator2>::value,
sprout::pair<RandomAccessIterator1, RandomAccessIterator2>
>::type
mismatch(
RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, RandomAccessIterator2 last2, BinaryPredicate pred,
std::random_access_iterator_tag*
)
{
return first1 == last1 || first2 == last2 ? sprout::pair<RandomAccessIterator1, RandomAccessIterator2>{first1, first2}
: sprout::detail::mismatch_impl_check(
first1, first2,
sprout::detail::mismatch2_impl_ra(
first1, last1, first2, last2, pred,
NS_SSCRISK_CEL_OR_SPROUT::min(sprout::distance(first1, last1), sprout::distance(first2, last2))
)
)
;
}
template<typename InputIterator1, typename InputIterator2>
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
mismatch2_impl_check(sprout::tuples::tuple<InputIterator1, InputIterator2, bool> const& current) {
return sprout::pair<InputIterator1, InputIterator2>(
sprout::tuples::get<0>(current),
sprout::tuples::get<1>(current)
);
}
template<typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<InputIterator1, InputIterator2, bool>
mismatch2_impl_1(
sprout::tuples::tuple<InputIterator1, InputIterator2, bool> const& current,
InputIterator1 last1, InputIterator2 last2, BinaryPredicate pred, typename std::iterator_traits<InputIterator1>::difference_type n
)
{
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, bool> type;
return sprout::tuples::get<2>(current) || sprout::tuples::get<0>(current) == last1 || sprout::tuples::get<1>(current) == last2 ? current
: n == 1 ? !pred(*sprout::tuples::get<0>(current), *sprout::tuples::get<1>(current))
? type(sprout::tuples::get<0>(current), sprout::tuples::get<1>(current), true)
: type(sprout::next(sprout::tuples::get<0>(current)), sprout::next(sprout::tuples::get<1>(current)), false)
: sprout::detail::mismatch2_impl_1(
sprout::detail::mismatch2_impl_1(
current,
last1, last2, pred, n / 2
),
last1, last2, pred, n - n / 2
)
;
}
template<typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<InputIterator1, InputIterator2, bool>
mismatch2_impl(
sprout::tuples::tuple<InputIterator1, InputIterator2, bool> const& current,
InputIterator1 last1, InputIterator2 last2, BinaryPredicate pred, typename std::iterator_traits<InputIterator1>::difference_type n
)
{
return sprout::tuples::get<2>(current) || sprout::tuples::get<0>(current) == last1 || sprout::tuples::get<1>(current) == last2 ? current
: sprout::detail::mismatch2_impl(
sprout::detail::mismatch2_impl_1(
current,
last1, last2, pred, n
),
last1, last2, pred, n * 2
)
;
}
template<typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
mismatch(
InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred,
std::input_iterator_tag*
)
{
typedef sprout::tuples::tuple<InputIterator1, InputIterator2, bool> type;
return sprout::detail::mismatch2_impl_check(
sprout::detail::mismatch2_impl(type(first1, first2, false), last1, last2, pred, 1)
);
}
} // namespace detail
// 25.2.10 Mismatch
//
// recursion depth:
// O(log N)
//
template<typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred) {
typedef typename sprout::common_iterator_category<InputIterator1, InputIterator2>::type* category;
return sprout::detail::mismatch(first1, last1, first2, last2, pred, category());
}
template<typename InputIterator1, typename InputIterator2>
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2) {
return sprout::mismatch(first1, last1, first2, last2, sprout::equal_to<>());
}
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_MISMATCH_HPP

View file

@ -8,8 +8,8 @@
#include <sprout/iterator/type_traits/category.hpp>
#include <sprout/iterator/type_traits/common.hpp>
#include <sprout/utility/pair/pair.hpp>
#include <sprout/algorithm/min.hpp>
#include <sprout/functional/less.hpp>
#include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT
namespace sprout {
namespace detail {
@ -79,7 +79,7 @@ namespace sprout {
: first1 == last1 ? -1
: sprout::detail::tristate_lexicographical_compare_impl_ra(
first1, last1, first2, last2, comp,
sprout::min(sprout::distance(first1, last1), sprout::distance(first2, last2))
NS_SSCRISK_CEL_OR_SPROUT::min(sprout::distance(first1, last1), sprout::distance(first2, last2))
)
;
}
@ -243,7 +243,7 @@ namespace sprout {
: first1 == last1 || (!comp(*first1, delim1) && !comp(delim1, *first1)) ? -1
: sprout::detail::tristate_lexicographical_compare_2_impl_ra(
first1, last1, delim1, first2, last2, delim2, comp,
sprout::min(sprout::distance(first1, last1), sprout::distance(first2, last2))
NS_SSCRISK_CEL_OR_SPROUT::min(sprout::distance(first1, last1), sprout::distance(first2, last2))
)
;
}