From 2893664abf2072dbc2e9a2e568cff145e188c734 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Wed, 15 Apr 2015 17:48:31 +0900 Subject: [PATCH] change while_loop signature --- sprout/utility/until_loop.hpp | 31 +++++++++++++++---------------- sprout/utility/while_loop.hpp | 31 +++++++++++++++---------------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/sprout/utility/until_loop.hpp b/sprout/utility/until_loop.hpp index 0cdfe5a8..5cad5bda 100644 --- a/sprout/utility/until_loop.hpp +++ b/sprout/utility/until_loop.hpp @@ -19,30 +19,30 @@ namespace sprout { until_loop_check(T const& init, Predicate pred) { return sprout::pair(init, pred(init)); } - template + template inline SPROUT_CONSTEXPR sprout::pair - until_loop_impl_1(sprout::pair const& current, UnaryOperation unary_op, Predicate pred, std::size_t n) { + until_loop_impl_1(sprout::pair const& current, Predicate pred, UnaryOperation unary_op, std::size_t n) { return current.second || pred(current.first) ? current : n == 1 ? sprout::detail::until_loop_check(unary_op(current.first), pred) : sprout::detail::until_loop_impl_1( sprout::detail::until_loop_impl_1( current, - unary_op, pred, n / 2 + pred, unary_op, n / 2 ), - unary_op, pred, n - n / 2 + pred, unary_op, n - n / 2 ) ; } - template + template inline SPROUT_CONSTEXPR sprout::pair - until_loop_impl(sprout::pair const& current, UnaryOperation unary_op, Predicate pred, std::size_t n) { + until_loop_impl(sprout::pair const& current, Predicate pred, UnaryOperation unary_op, std::size_t n) { return current.second || pred(current.first) ? current : sprout::detail::until_loop_impl( sprout::detail::until_loop_impl_1( 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: // O(log N) // - template + template 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 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 // @@ -67,12 +67,11 @@ namespace sprout { // recursion depth: // 0 // - template + template inline SPROUT_CXX14_CONSTEXPR T - until_loop(T init, UnaryOperation unary_op, Predicate pred) { - while (!pred(init)) { - init = unary_op(init); - } + until_loop(T init, Predicate pred, UnaryOperation unary_op) { + for (; !pred(init); init = unary_op(init)) + ; return init; } #endif diff --git a/sprout/utility/while_loop.hpp b/sprout/utility/while_loop.hpp index 3e2f638d..809f3c7f 100644 --- a/sprout/utility/while_loop.hpp +++ b/sprout/utility/while_loop.hpp @@ -19,30 +19,30 @@ namespace sprout { while_loop_check(T const& init, Predicate pred) { return sprout::pair(init, !pred(init)); } - template + template inline SPROUT_CONSTEXPR sprout::pair - while_loop_impl_1(sprout::pair const& current, UnaryOperation unary_op, Predicate pred, std::size_t n) { + while_loop_impl_1(sprout::pair const& current, Predicate pred, UnaryOperation unary_op, std::size_t n) { return current.second || !pred(current.first) ? current : n == 1 ? sprout::detail::while_loop_check(unary_op(current.first), pred) : sprout::detail::while_loop_impl_1( sprout::detail::while_loop_impl_1( current, - unary_op, pred, n / 2 + pred, unary_op, n / 2 ), - unary_op, pred, n - n / 2 + pred, unary_op, n - n / 2 ) ; } - template + template inline SPROUT_CONSTEXPR sprout::pair - while_loop_impl(sprout::pair const& current, UnaryOperation unary_op, Predicate pred, std::size_t n) { + while_loop_impl(sprout::pair const& current, Predicate pred, UnaryOperation unary_op, std::size_t n) { return current.second || !pred(current.first) ? current : sprout::detail::while_loop_impl( sprout::detail::while_loop_impl_1( 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: // O(log N) // - template + template 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 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 // @@ -67,12 +67,11 @@ namespace sprout { // recursion depth: // 0 // - template + template inline SPROUT_CXX14_CONSTEXPR T - while_loop(T init, UnaryOperation unary_op, Predicate pred) { - while (pred(init)) { - init = unary_op(init); - } + while_loop(T init, Predicate pred, UnaryOperation unary_op) { + for (; pred(init); init = unary_op(init)) + ; return init; } #endif