mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
change while_loop signature
This commit is contained in:
parent
8d19fdc676
commit
2893664abf
2 changed files with 30 additions and 32 deletions
|
@ -19,30 +19,30 @@ namespace sprout {
|
||||||
until_loop_check(T const& init, Predicate pred) {
|
until_loop_check(T const& init, Predicate pred) {
|
||||||
return sprout::pair<T, bool>(init, pred(init));
|
return sprout::pair<T, bool>(init, pred(init));
|
||||||
}
|
}
|
||||||
template<typename T, typename UnaryOperation, typename Predicate>
|
template<typename T, typename Predicate, typename UnaryOperation>
|
||||||
inline SPROUT_CONSTEXPR sprout::pair<T, bool>
|
inline SPROUT_CONSTEXPR sprout::pair<T, bool>
|
||||||
until_loop_impl_1(sprout::pair<T, bool> const& current, UnaryOperation unary_op, Predicate pred, std::size_t n) {
|
until_loop_impl_1(sprout::pair<T, bool> const& current, Predicate pred, UnaryOperation unary_op, std::size_t n) {
|
||||||
return current.second || pred(current.first) ? current
|
return current.second || pred(current.first) ? current
|
||||||
: n == 1 ? sprout::detail::until_loop_check<T>(unary_op(current.first), pred)
|
: n == 1 ? sprout::detail::until_loop_check<T>(unary_op(current.first), pred)
|
||||||
: sprout::detail::until_loop_impl_1(
|
: sprout::detail::until_loop_impl_1(
|
||||||
sprout::detail::until_loop_impl_1(
|
sprout::detail::until_loop_impl_1(
|
||||||
current,
|
current,
|
||||||
unary_op, pred, n / 2
|
pred, unary_op, n / 2
|
||||||
),
|
),
|
||||||
unary_op, pred, n - n / 2
|
pred, unary_op, n - n / 2
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
template<typename T, typename UnaryOperation, typename Predicate>
|
template<typename T, typename Predicate, typename UnaryOperation>
|
||||||
inline SPROUT_CONSTEXPR sprout::pair<T, bool>
|
inline SPROUT_CONSTEXPR sprout::pair<T, bool>
|
||||||
until_loop_impl(sprout::pair<T, bool> const& current, UnaryOperation unary_op, Predicate pred, std::size_t n) {
|
until_loop_impl(sprout::pair<T, bool> const& current, Predicate pred, UnaryOperation unary_op, std::size_t n) {
|
||||||
return current.second || pred(current.first) ? current
|
return current.second || pred(current.first) ? current
|
||||||
: sprout::detail::until_loop_impl(
|
: sprout::detail::until_loop_impl(
|
||||||
sprout::detail::until_loop_impl_1(
|
sprout::detail::until_loop_impl_1(
|
||||||
current,
|
current,
|
||||||
unary_op, pred, n
|
pred, unary_op, n
|
||||||
),
|
),
|
||||||
unary_op, pred, n * 2
|
pred, unary_op, n * 2
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -54,11 +54,11 @@ namespace sprout {
|
||||||
// recursion depth:
|
// recursion depth:
|
||||||
// O(log N)
|
// O(log N)
|
||||||
//
|
//
|
||||||
template<typename T, typename UnaryOperation, typename Predicate>
|
template<typename T, typename Predicate, typename UnaryOperation>
|
||||||
inline SPROUT_CONSTEXPR T
|
inline SPROUT_CONSTEXPR T
|
||||||
until_loop(T init, UnaryOperation unary_op, Predicate pred) {
|
until_loop(T init, Predicate pred, UnaryOperation unary_op) {
|
||||||
typedef sprout::pair<T, bool> type;
|
typedef sprout::pair<T, bool> type;
|
||||||
return sprout::detail::until_loop_impl(type(init, false), unary_op, pred, 1).second;
|
return sprout::detail::until_loop_impl(type(init, false), pred, unary_op, 1).second;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
//
|
//
|
||||||
|
@ -67,12 +67,11 @@ namespace sprout {
|
||||||
// recursion depth:
|
// recursion depth:
|
||||||
// 0
|
// 0
|
||||||
//
|
//
|
||||||
template<typename T, typename UnaryOperation, typename Predicate>
|
template<typename T, typename Predicate, typename UnaryOperation>
|
||||||
inline SPROUT_CXX14_CONSTEXPR T
|
inline SPROUT_CXX14_CONSTEXPR T
|
||||||
until_loop(T init, UnaryOperation unary_op, Predicate pred) {
|
until_loop(T init, Predicate pred, UnaryOperation unary_op) {
|
||||||
while (!pred(init)) {
|
for (; !pred(init); init = unary_op(init))
|
||||||
init = unary_op(init);
|
;
|
||||||
}
|
|
||||||
return init;
|
return init;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,30 +19,30 @@ namespace sprout {
|
||||||
while_loop_check(T const& init, Predicate pred) {
|
while_loop_check(T const& init, Predicate pred) {
|
||||||
return sprout::pair<T, bool>(init, !pred(init));
|
return sprout::pair<T, bool>(init, !pred(init));
|
||||||
}
|
}
|
||||||
template<typename T, typename UnaryOperation, typename Predicate>
|
template<typename T, typename Predicate, typename UnaryOperation>
|
||||||
inline SPROUT_CONSTEXPR sprout::pair<T, bool>
|
inline SPROUT_CONSTEXPR sprout::pair<T, bool>
|
||||||
while_loop_impl_1(sprout::pair<T, bool> const& current, UnaryOperation unary_op, Predicate pred, std::size_t n) {
|
while_loop_impl_1(sprout::pair<T, bool> const& current, Predicate pred, UnaryOperation unary_op, std::size_t n) {
|
||||||
return current.second || !pred(current.first) ? current
|
return current.second || !pred(current.first) ? current
|
||||||
: n == 1 ? sprout::detail::while_loop_check<T>(unary_op(current.first), pred)
|
: n == 1 ? sprout::detail::while_loop_check<T>(unary_op(current.first), pred)
|
||||||
: sprout::detail::while_loop_impl_1(
|
: sprout::detail::while_loop_impl_1(
|
||||||
sprout::detail::while_loop_impl_1(
|
sprout::detail::while_loop_impl_1(
|
||||||
current,
|
current,
|
||||||
unary_op, pred, n / 2
|
pred, unary_op, n / 2
|
||||||
),
|
),
|
||||||
unary_op, pred, n - n / 2
|
pred, unary_op, n - n / 2
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
template<typename T, typename UnaryOperation, typename Predicate>
|
template<typename T, typename Predicate, typename UnaryOperation>
|
||||||
inline SPROUT_CONSTEXPR sprout::pair<T, bool>
|
inline SPROUT_CONSTEXPR sprout::pair<T, bool>
|
||||||
while_loop_impl(sprout::pair<T, bool> const& current, UnaryOperation unary_op, Predicate pred, std::size_t n) {
|
while_loop_impl(sprout::pair<T, bool> const& current, Predicate pred, UnaryOperation unary_op, std::size_t n) {
|
||||||
return current.second || !pred(current.first) ? current
|
return current.second || !pred(current.first) ? current
|
||||||
: sprout::detail::while_loop_impl(
|
: sprout::detail::while_loop_impl(
|
||||||
sprout::detail::while_loop_impl_1(
|
sprout::detail::while_loop_impl_1(
|
||||||
current,
|
current,
|
||||||
unary_op, pred, n
|
pred, unary_op, n
|
||||||
),
|
),
|
||||||
unary_op, pred, n * 2
|
pred, unary_op, n * 2
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -54,11 +54,11 @@ namespace sprout {
|
||||||
// recursion depth:
|
// recursion depth:
|
||||||
// O(log N)
|
// O(log N)
|
||||||
//
|
//
|
||||||
template<typename T, typename UnaryOperation, typename Predicate>
|
template<typename T, typename Predicate, typename UnaryOperation>
|
||||||
inline SPROUT_CONSTEXPR T
|
inline SPROUT_CONSTEXPR T
|
||||||
while_loop(T init, UnaryOperation unary_op, Predicate pred) {
|
while_loop(T init, Predicate pred, UnaryOperation unary_op) {
|
||||||
typedef sprout::pair<T, bool> type;
|
typedef sprout::pair<T, bool> type;
|
||||||
return sprout::detail::while_loop_impl(type(init, false), unary_op, pred, 1).second;
|
return sprout::detail::while_loop_impl(type(init, false), pred, unary_op, 1).second;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
//
|
//
|
||||||
|
@ -67,12 +67,11 @@ namespace sprout {
|
||||||
// recursion depth:
|
// recursion depth:
|
||||||
// 0
|
// 0
|
||||||
//
|
//
|
||||||
template<typename T, typename UnaryOperation, typename Predicate>
|
template<typename T, typename Predicate, typename UnaryOperation>
|
||||||
inline SPROUT_CXX14_CONSTEXPR T
|
inline SPROUT_CXX14_CONSTEXPR T
|
||||||
while_loop(T init, UnaryOperation unary_op, Predicate pred) {
|
while_loop(T init, Predicate pred, UnaryOperation unary_op) {
|
||||||
while (pred(init)) {
|
for (; pred(init); init = unary_op(init))
|
||||||
init = unary_op(init);
|
;
|
||||||
}
|
|
||||||
return init;
|
return init;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue