mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
fix next|prev_permutation implementations
This commit is contained in:
parent
057dec630c
commit
2c0b1d4513
8 changed files with 150 additions and 141 deletions
|
@ -59,7 +59,6 @@ namespace sprout {
|
|||
typename std::iterator_traits<RandomAccessIterator>::difference_type len
|
||||
)
|
||||
{
|
||||
typedef typename std::iterator_traits<RandomAccessIterator>::difference_type difference_type;
|
||||
typedef typename std::iterator_traits<RandomAccessIterator>::value_type value_type;
|
||||
if (len > 1) {
|
||||
len = (len - 2) / 2;
|
||||
|
|
|
@ -15,8 +15,14 @@
|
|||
#include <sprout/algorithm/fixed/results.hpp>
|
||||
#include <sprout/algorithm/fixed/swap_element.hpp>
|
||||
#include <sprout/algorithm/fixed/reverse_copy.hpp>
|
||||
#include <sprout/algorithm/fixed/reverse.hpp>
|
||||
#include <sprout/sub_array/sub_array.hpp>
|
||||
#include <sprout/detail/predef.hpp>
|
||||
#if SPROUT_GCC_EARLIER(4, 8, 2)
|
||||
# include <sprout/algorithm/fit/reverse_copy.hpp>
|
||||
# include <sprout/range/algorithm/fixed/copy_backward.hpp>
|
||||
#else
|
||||
# include <sprout/iterator/reverse_iterator.hpp>
|
||||
# include <sprout/algorithm/fixed/copy_backward.hpp>
|
||||
#endif
|
||||
#include <sprout/utility/pair/pair.hpp>
|
||||
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
|
@ -27,7 +33,11 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR Result
|
||||
next_permutation_impl_4(Container const& cont, Difference d) {
|
||||
return Result(
|
||||
sprout::get_internal(sprout::fixed::reverse(sprout::sub_array<Container const&>(cont, d, sprout::size(cont)))),
|
||||
#if SPROUT_GCC_EARLIER(4, 8, 2)
|
||||
sprout::range::fixed::copy_backward(sprout::fit::reverse_copy(sprout::next(sprout::begin(cont), d), sprout::end(cont), cont), cont),
|
||||
#else
|
||||
sprout::fixed::copy_backward(sprout::make_reverse_iterator(sprout::end(cont)), sprout::make_reverse_iterator(sprout::next(sprout::begin(cont), d)), cont),
|
||||
#endif
|
||||
true
|
||||
);
|
||||
}
|
||||
|
|
|
@ -15,8 +15,14 @@
|
|||
#include <sprout/algorithm/fixed/results.hpp>
|
||||
#include <sprout/algorithm/fixed/swap_element.hpp>
|
||||
#include <sprout/algorithm/fixed/reverse_copy.hpp>
|
||||
#include <sprout/algorithm/fixed/reverse.hpp>
|
||||
#include <sprout/sub_array/sub_array.hpp>
|
||||
#include <sprout/detail/predef.hpp>
|
||||
#if SPROUT_GCC_EARLIER(4, 8, 2)
|
||||
# include <sprout/algorithm/fit/reverse_copy.hpp>
|
||||
# include <sprout/range/algorithm/fixed/copy_backward.hpp>
|
||||
#else
|
||||
# include <sprout/iterator/reverse_iterator.hpp>
|
||||
# include <sprout/algorithm/fixed/copy_backward.hpp>
|
||||
#endif
|
||||
#include <sprout/utility/pair/pair.hpp>
|
||||
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
|
@ -27,7 +33,11 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR Result
|
||||
prev_permutation_impl_4(Container const& cont, Difference d) {
|
||||
return Result(
|
||||
sprout::get_internal(sprout::fixed::reverse(sprout::sub_array<Container const&>(cont, d, sprout::size(cont)))),
|
||||
#if SPROUT_GCC_EARLIER(4, 8, 2)
|
||||
sprout::range::fixed::copy_backward(sprout::fit::reverse_copy(sprout::next(sprout::begin(cont), d), sprout::end(cont), cont), cont),
|
||||
#else
|
||||
sprout::fixed::copy_backward(sprout::make_reverse_iterator(sprout::end(cont)), sprout::make_reverse_iterator(sprout::next(sprout::begin(cont), d)), cont),
|
||||
#endif
|
||||
true
|
||||
);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include <climits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
//#include <sprout/bit/popcount.hpp>
|
||||
#include <sprout/bit/shlr.hpp>
|
||||
|
||||
namespace sprout {
|
||||
|
@ -31,11 +30,6 @@ namespace sprout {
|
|||
return __builtin_parityll(x);
|
||||
}
|
||||
# endif
|
||||
// template<typename Integral>
|
||||
// inline SPROUT_CONSTEXPR int
|
||||
// parity(Integral x) {
|
||||
// return sprout::popcount(x) & 1;
|
||||
// }
|
||||
template<std::size_t N, typename Integral>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
(N == 1),
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace sprout {
|
|||
typename sprout::fixed::results::algorithm<Result>::type
|
||||
>::type
|
||||
container_complate_backward_2(Result const& result, Args const&... args) {
|
||||
return container_complate_backward_2(result, *sprout::prev(sprout::internal_end(result), sizeof...(Args) + 1), args...);
|
||||
return sprout::detail::container_complate_backward_2(result, *sprout::prev(sprout::internal_end(result), sizeof...(Args) + 1), args...);
|
||||
}
|
||||
template<typename Result, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
|
@ -58,8 +58,8 @@ namespace sprout {
|
|||
)
|
||||
{
|
||||
return remain != 0
|
||||
? container_complate_backward_1(result, remain - 1, args..., *sprout::prev(sprout::internal_end(result), remain))
|
||||
: container_complate_backward_2(result, args...)
|
||||
? sprout::detail::container_complate_backward_1(result, remain - 1, args..., *sprout::prev(sprout::internal_end(result), remain))
|
||||
: sprout::detail::container_complate_backward_2(result, args...)
|
||||
;
|
||||
}
|
||||
template<typename Result, typename... Args>
|
||||
|
@ -76,7 +76,7 @@ namespace sprout {
|
|||
typename sprout::fixed::results::algorithm<Result>::type
|
||||
>::type
|
||||
container_complate_backward(Result const& result, Args const&... args) {
|
||||
return container_complate_backward_1(result, sprout::internal_end_offset_backward(result), args...);
|
||||
return sprout::detail::container_complate_backward_1(result, sprout::internal_end_offset_backward(result), args...);
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue