mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-04 14:14:09 +00:00
porting sscrisk/CEL
This commit is contained in:
parent
ad60c8c530
commit
db20f64991
181 changed files with 2531 additions and 607 deletions
74
sprout/algorithm/is_permutation.hpp
Normal file
74
sprout/algorithm/is_permutation.hpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
#ifndef SPROUT_ALGORITHM_IS_PERMUTATION_HPP
|
||||
#define SPROUT_ALGORITHM_IS_PERMUTATION_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/algorithm/count.hpp>
|
||||
#include <sprout/algorithm/count_if.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
namespace detail {
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
SPROUT_CONSTEXPR bool is_permutation_impl(
|
||||
ForwardIterator1 first1,
|
||||
ForwardIterator1 last1,
|
||||
ForwardIterator2 first2,
|
||||
ForwardIterator1 first1_
|
||||
)
|
||||
{
|
||||
return first1_ == last1 ? true
|
||||
: sprout::count(first1, last1, *first1_)
|
||||
== sprout::count(first2, first2 + NS_SSCRISK_CEL_OR_SPROUT::distance(first1, last1), *first1_)
|
||||
&& sprout::detail::is_permutation_impl(first1, last1, first2, sprout::next(first1_))
|
||||
? true
|
||||
: false
|
||||
;
|
||||
}
|
||||
|
||||
template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
|
||||
SPROUT_CONSTEXPR bool is_permutation_impl(
|
||||
ForwardIterator1 first1,
|
||||
ForwardIterator1 last1,
|
||||
ForwardIterator2 first2,
|
||||
ForwardIterator1 first1_,
|
||||
BinaryPredicate pred
|
||||
)
|
||||
{
|
||||
return first1_ == last1 ? true
|
||||
: sprout::count_if(first1, last1, NS_SSCRISK_CEL_OR_SPROUT::bind2nd(pred, *first1_))
|
||||
== sprout::count_if(first2, first2 + NS_SSCRISK_CEL_OR_SPROUT::distance(first1, last1), NS_SSCRISK_CEL_OR_SPROUT::bind2nd(pred, *first1_))
|
||||
&& sprout::detail::is_permutation_impl(first1, last1, first2, sprout::next(first1_), pred)
|
||||
? true
|
||||
: false
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
// 25.2.12 Is permutation
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
SPROUT_CONSTEXPR bool is_permutation(
|
||||
ForwardIterator1 first1,
|
||||
ForwardIterator1 last1,
|
||||
ForwardIterator2 first2
|
||||
)
|
||||
{
|
||||
return sprout::detail::is_permutation_impl(first1, last1, first2, first1);
|
||||
}
|
||||
|
||||
template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
|
||||
SPROUT_CONSTEXPR bool is_permutation(
|
||||
ForwardIterator1 first1,
|
||||
ForwardIterator1 last1,
|
||||
ForwardIterator2 first2,
|
||||
BinaryPredicate pred
|
||||
)
|
||||
{
|
||||
return sprout::detail::is_permutation_impl(first1, last1, first2, first1, pred);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_IS_PERMUTATION_HPP
|
Loading…
Add table
Add a link
Reference in a new issue