mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-05-10 09:23:30 +00:00
add utility flat_while_loop/flat_until_loop
This commit is contained in:
parent
99860f4bc7
commit
7233a268fd
2 changed files with 6 additions and 10 deletions
|
@ -12,7 +12,6 @@
|
||||||
#include <sprout/utility/pair/pair.hpp>
|
#include <sprout/utility/pair/pair.hpp>
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
#ifdef SPROUT_CONFIG_DISABLE_CXX14_CONSTEXPR
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<typename T, typename Predicate>
|
template<typename T, typename Predicate>
|
||||||
inline SPROUT_CONSTEXPR sprout::pair<T, bool>
|
inline SPROUT_CONSTEXPR sprout::pair<T, bool>
|
||||||
|
@ -60,21 +59,20 @@ namespace sprout {
|
||||||
typedef sprout::pair<T, bool> type;
|
typedef sprout::pair<T, bool> type;
|
||||||
return sprout::detail::until_loop_impl(type(init, false), pred, unary_op, 1).second;
|
return sprout::detail::until_loop_impl(type(init, false), pred, unary_op, 1).second;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
//
|
//
|
||||||
// until_loop
|
// flat_until_loop
|
||||||
//
|
//
|
||||||
// recursion depth:
|
// recursion depth:
|
||||||
// 0
|
// 0
|
||||||
//
|
//
|
||||||
template<typename T, typename Predicate, typename UnaryOperation>
|
template<typename T, typename Predicate, typename UnaryOperation>
|
||||||
inline SPROUT_CXX14_CONSTEXPR T
|
inline SPROUT_CXX14_CONSTEXPR T
|
||||||
until_loop(T init, Predicate pred, UnaryOperation unary_op) {
|
flat_until_loop(T init, Predicate pred, UnaryOperation unary_op) {
|
||||||
for (; !pred(init); init = unary_op(init))
|
for (; !pred(init); init = unary_op(init))
|
||||||
;
|
;
|
||||||
return init;
|
return init;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_UTILITY_UNTIL_LOOP_HPP
|
#endif // #ifndef SPROUT_UTILITY_UNTIL_LOOP_HPP
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include <sprout/utility/pair/pair.hpp>
|
#include <sprout/utility/pair/pair.hpp>
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
#ifdef SPROUT_CONFIG_DISABLE_CXX14_CONSTEXPR
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<typename T, typename Predicate>
|
template<typename T, typename Predicate>
|
||||||
inline SPROUT_CONSTEXPR sprout::pair<T, bool>
|
inline SPROUT_CONSTEXPR sprout::pair<T, bool>
|
||||||
|
@ -60,21 +59,20 @@ namespace sprout {
|
||||||
typedef sprout::pair<T, bool> type;
|
typedef sprout::pair<T, bool> type;
|
||||||
return sprout::detail::while_loop_impl(type(init, false), pred, unary_op, 1).second;
|
return sprout::detail::while_loop_impl(type(init, false), pred, unary_op, 1).second;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
//
|
//
|
||||||
// while_loop
|
// flat_while_loop
|
||||||
//
|
//
|
||||||
// recursion depth:
|
// recursion depth:
|
||||||
// 0
|
// 0
|
||||||
//
|
//
|
||||||
template<typename T, typename Predicate, typename UnaryOperation>
|
template<typename T, typename Predicate, typename UnaryOperation>
|
||||||
inline SPROUT_CXX14_CONSTEXPR T
|
inline SPROUT_CXX14_CONSTEXPR T
|
||||||
while_loop(T init, Predicate pred, UnaryOperation unary_op) {
|
flat_while_loop(T init, Predicate pred, UnaryOperation unary_op) {
|
||||||
for (; pred(init); init = unary_op(init))
|
for (; pred(init); init = unary_op(init))
|
||||||
;
|
;
|
||||||
return init;
|
return init;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_UTILITY_WHILE_LOOP_HPP
|
#endif // #ifndef SPROUT_UTILITY_WHILE_LOOP_HPP
|
||||||
|
|
Loading…
Add table
Reference in a new issue