mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-12 14:54:10 +00:00
add is_permutation algorithm: robust version (N3607)
This commit is contained in:
parent
d6aaabe45f
commit
d732a73431
3 changed files with 308 additions and 36 deletions
|
@ -126,37 +126,23 @@ namespace sprout {
|
|||
|
||||
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
equal2_impl_ra_1(
|
||||
equal2_impl_ra(
|
||||
RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, RandomAccessIterator2 last2, BinaryPredicate pred,
|
||||
typename std::iterator_traits<RandomAccessIterator1>::difference_type pivot
|
||||
)
|
||||
{
|
||||
return pivot == 0 ? pred(*first1, *first2)
|
||||
: sprout::detail::equal2_impl_ra_1(
|
||||
: sprout::detail::equal2_impl_ra(
|
||||
first1, sprout::next(first1, pivot), first2, sprout::next(first2, pivot), pred,
|
||||
pivot / 2
|
||||
)
|
||||
&& sprout::detail::equal2_impl_ra_1(
|
||||
&& sprout::detail::equal2_impl_ra(
|
||||
sprout::next(first1, pivot), last1, sprout::next(first2, pivot), last2, pred,
|
||||
(sprout::distance(first1, last1) - pivot) / 2
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
equal2_impl_ra(
|
||||
RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, RandomAccessIterator2 last2, BinaryPredicate pred,
|
||||
typename std::iterator_traits<RandomAccessIterator1>::difference_type size1, typename std::iterator_traits<RandomAccessIterator1>::difference_type size2
|
||||
)
|
||||
{
|
||||
return size1 == size2
|
||||
&& sprout::detail::equal2_impl_ra_1(
|
||||
first1, last1, first2, last2, pred,
|
||||
size1 / 2
|
||||
)
|
||||
;
|
||||
}
|
||||
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,
|
||||
bool
|
||||
|
@ -166,10 +152,12 @@ namespace sprout {
|
|||
std::random_access_iterator_tag*
|
||||
)
|
||||
{
|
||||
return sprout::detail::equal2_impl_ra(
|
||||
first1, last1, first2, last2, pred,
|
||||
sprout::distance(first1, last1), sprout::distance(first2, last2)
|
||||
);
|
||||
return sprout::distance(first1, last1) == sprout::distance(first2, last2)
|
||||
&& sprout::detail::equal2_impl_ra(
|
||||
first1, last1, first2, last2, pred,
|
||||
sprout::distance(first1, last1) / 2
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue