From 2052058357bd14be227674f68aa54e69f4c6257b Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Tue, 10 Oct 2017 02:13:04 +0900 Subject: [PATCH] add numeric algorithm reduce, exclusive_scan, inclusize_scan --- sprout/algorithm/fixed/results.hpp | 34 ++- sprout/numeric/adjacent_difference.hpp | 1 + sprout/numeric/cxx14.hpp | 2 + sprout/numeric/cxx14/exclusive_scan.hpp | 54 +++++ sprout/numeric/cxx14/inclusive_scan.hpp | 59 +++++ sprout/numeric/exclusive_scan.hpp | 16 ++ sprout/numeric/fit.hpp | 2 + sprout/numeric/fit/exclusive_scan.hpp | 77 ++++++ sprout/numeric/fit/inclusive_scan.hpp | 102 ++++++++ sprout/numeric/fixed.hpp | 2 + sprout/numeric/fixed/exclusive_scan.hpp | 229 ++++++++++++++++++ sprout/numeric/fixed/inclusive_scan.hpp | 147 +++++++++++ sprout/numeric/inclusive_scan.hpp | 16 ++ sprout/numeric/iota.hpp | 1 + sprout/numeric/non_modifying.hpp | 1 + sprout/numeric/partial_sum.hpp | 1 + sprout/numeric/reduce.hpp | 42 ++++ sprout/range/numeric/accumulate.hpp | 2 + sprout/range/numeric/cxx14.hpp | 2 + sprout/range/numeric/cxx14/exclusive_scan.hpp | 42 ++++ sprout/range/numeric/cxx14/inclusive_scan.hpp | 50 ++++ sprout/range/numeric/exclusive_scan.hpp | 15 ++ sprout/range/numeric/fit.hpp | 2 + sprout/range/numeric/fit/exclusive_scan.hpp | 48 ++++ sprout/range/numeric/fit/inclusive_scan.hpp | 58 +++++ sprout/range/numeric/fixed.hpp | 2 + sprout/range/numeric/fixed/exclusive_scan.hpp | 58 +++++ sprout/range/numeric/fixed/inclusive_scan.hpp | 71 ++++++ sprout/range/numeric/inclusive_scan.hpp | 15 ++ sprout/range/numeric/inner_product.hpp | 2 + sprout/range/numeric/non_modifying.hpp | 1 + sprout/range/numeric/reduce.hpp | 41 ++++ sprout/sub_array/container.hpp | 4 +- testspr/trace.hpp | 14 +- 34 files changed, 1195 insertions(+), 18 deletions(-) create mode 100644 sprout/numeric/cxx14/exclusive_scan.hpp create mode 100644 sprout/numeric/cxx14/inclusive_scan.hpp create mode 100644 sprout/numeric/exclusive_scan.hpp create mode 100644 sprout/numeric/fit/exclusive_scan.hpp create mode 100644 sprout/numeric/fit/inclusive_scan.hpp create mode 100644 sprout/numeric/fixed/exclusive_scan.hpp create mode 100644 sprout/numeric/fixed/inclusive_scan.hpp create mode 100644 sprout/numeric/inclusive_scan.hpp create mode 100644 sprout/numeric/reduce.hpp create mode 100644 sprout/range/numeric/cxx14/exclusive_scan.hpp create mode 100644 sprout/range/numeric/cxx14/inclusive_scan.hpp create mode 100644 sprout/range/numeric/exclusive_scan.hpp create mode 100644 sprout/range/numeric/fit/exclusive_scan.hpp create mode 100644 sprout/range/numeric/fit/inclusive_scan.hpp create mode 100644 sprout/range/numeric/fixed/exclusive_scan.hpp create mode 100644 sprout/range/numeric/fixed/inclusive_scan.hpp create mode 100644 sprout/range/numeric/inclusive_scan.hpp create mode 100644 sprout/range/numeric/reduce.hpp diff --git a/sprout/algorithm/fixed/results.hpp b/sprout/algorithm/fixed/results.hpp index f242dd8b..ba0a6a4c 100644 --- a/sprout/algorithm/fixed/results.hpp +++ b/sprout/algorithm/fixed/results.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace sprout { namespace fixed { @@ -20,22 +21,33 @@ namespace sprout { // algorithm // template - struct algorithm { - public: - typedef typename sprout::container_construct_traits::copied_type type; - }; + struct algorithm + : public sprout::identity::copied_type> + {}; + + // + // resized_relative + // + template::difference_type RelativeSize> + struct resized_relative + : public sprout::identity< + typename sprout::container_transform_traits + ::template rebind_size::static_size + RelativeSize>::type + > + {}; // // shuffle // template - struct shuffle { - public: - typedef sprout::pair< - typename sprout::fixed::results::algorithm::type, - typename std::decay::type - > type; - }; + struct shuffle + : public sprout::identity< + sprout::pair< + typename sprout::fixed::results::algorithm::type, + typename std::decay::type + > + > + {}; } // namespace results } // namespace fixed diff --git a/sprout/numeric/adjacent_difference.hpp b/sprout/numeric/adjacent_difference.hpp index 3bc1ae5d..d5ec2a55 100644 --- a/sprout/numeric/adjacent_difference.hpp +++ b/sprout/numeric/adjacent_difference.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_NUMERIC_ADJACENT_DIFFERENCE_HPP diff --git a/sprout/numeric/cxx14.hpp b/sprout/numeric/cxx14.hpp index f95569fe..aabc6108 100644 --- a/sprout/numeric/cxx14.hpp +++ b/sprout/numeric/cxx14.hpp @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include diff --git a/sprout/numeric/cxx14/exclusive_scan.hpp b/sprout/numeric/cxx14/exclusive_scan.hpp new file mode 100644 index 00000000..88058e73 --- /dev/null +++ b/sprout/numeric/cxx14/exclusive_scan.hpp @@ -0,0 +1,54 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_NUMERIC_CXX14_EXCLUSIVE_SCAN_HPP +#define SPROUT_NUMERIC_CXX14_EXCLUSIVE_SCAN_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + // + // 29.8.7 Exclusive scan + // + template< + typename InputIterator, typename OutputIterator, typename T, typename BinaryOperation, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CXX14_CONSTEXPR OutputIterator + exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, BinaryOperation binary_op) { + typedef typename std::iterator_traits::value_type value_type; + value_type sum = sprout::move(init); + *result = sum; + if (first == last) { + return ++result; + } + value_type temp = *first; + while (++first != last) { + sum = binary_op(sum, temp); + *++result = sum; + temp = *first; + } + return ++result; + } + template< + typename InputIterator, typename OutputIterator, typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CXX14_CONSTEXPR OutputIterator + exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init) { + return sprout::exclusive_scan( + first, last, result, init, + NS_SSCRISK_CEL_OR_SPROUT::plus::value_type>() + ); + } +} // namespace sprout + +#endif // #ifndef SPROUT_NUMERIC_CXX14_EXCLUSIVE_SCAN_HPP diff --git a/sprout/numeric/cxx14/inclusive_scan.hpp b/sprout/numeric/cxx14/inclusive_scan.hpp new file mode 100644 index 00000000..8bcf6a21 --- /dev/null +++ b/sprout/numeric/cxx14/inclusive_scan.hpp @@ -0,0 +1,59 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_NUMERIC_CXX14_INCLUSIVE_SCAN_HPP +#define SPROUT_NUMERIC_CXX14_INCLUSIVE_SCAN_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + // + // 29.8.8 Inclusive scan + // + template< + typename InputIterator, typename OutputIterator, typename BinaryOperation, typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CXX14_CONSTEXPR OutputIterator + inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op, T init) { + typedef typename std::iterator_traits::value_type value_type; + value_type sum = sprout::move(init); + *result = sum; + if (first == last) { + return ++result; + } + sum = binary_op(sum, *first); + *++result = sum; + while (++first != last) { + sum = binary_op(sum, *first); + *++result = sum; + } + return ++result; + } + template< + typename InputIterator, typename OutputIterator, typename BinaryOperation, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CXX14_CONSTEXPR OutputIterator + inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op) { + return sprout::partial_sum(first, last, result, binary_op); + } + template< + typename InputIterator, typename OutputIterator, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CXX14_CONSTEXPR OutputIterator + inclusive_scan(InputIterator first, InputIterator last, OutputIterator result) { + return sprout::partial_sum(first, last, result); + } +} // namespace sprout + +#endif // #ifndef SPROUT_NUMERIC_CXX14_INCLUSIVE_SCAN_HPP diff --git a/sprout/numeric/exclusive_scan.hpp b/sprout/numeric/exclusive_scan.hpp new file mode 100644 index 00000000..7b01933d --- /dev/null +++ b/sprout/numeric/exclusive_scan.hpp @@ -0,0 +1,16 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_NUMERIC_EXCLUSIVE_SCAN_HPP +#define SPROUT_NUMERIC_EXCLUSIVE_SCAN_HPP + +#include +#include +#include +#include + +#endif // #ifndef SPROUT_NUMERIC_EXCLUSIVE_SCAN_HPP diff --git a/sprout/numeric/fit.hpp b/sprout/numeric/fit.hpp index 00aebae2..25ab21be 100644 --- a/sprout/numeric/fit.hpp +++ b/sprout/numeric/fit.hpp @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include diff --git a/sprout/numeric/fit/exclusive_scan.hpp b/sprout/numeric/fit/exclusive_scan.hpp new file mode 100644 index 00000000..38b43033 --- /dev/null +++ b/sprout/numeric/fit/exclusive_scan.hpp @@ -0,0 +1,77 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_NUMERIC_FIT_EXCLUSIVE_SCAN_HPP +#define SPROUT_NUMERIC_FIT_EXCLUSIVE_SCAN_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace fit { + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + exclusive_scan_impl( + InputIterator const& first, InputIterator const& last, Result const& result, T init, + typename sprout::container_traits::difference_type offset + ) + { + typedef typename std::iterator_traits::difference_type diff_type; + return sprout::sub_copy( + sprout::get_internal(sprout::fixed::exclusive_scan(first, last, result, init)), + offset, + offset + NS_SSCRISK_CEL_OR_SPROUT::min(sprout::distance(first, last), sprout::size(result)) + ); + } + } // namespace detail + // + // exclusive_scan + // + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + exclusive_scan(InputIterator first, InputIterator last, Result const& result, T init) { + static_assert(sprout::is_forward_iterator::value, "Sorry, not implemented."); + return sprout::fit::detail::exclusive_scan_impl(first, last, result, init, sprout::internal_begin_offset(result)); + } + + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + exclusive_scan_impl( + InputIterator const& first, InputIterator const& last, Result const& result, T init, BinaryOperation binary_op, + typename sprout::container_traits::difference_type offset + ) + { + typedef typename std::iterator_traits::difference_type diff_type; + return sprout::sub_copy( + sprout::get_internal(sprout::fixed::exclusive_scan(first, last, result, init, binary_op)), + offset, + offset + NS_SSCRISK_CEL_OR_SPROUT::min(sprout::distance(first, last), sprout::size(result)) + ); + } + } // namespace detail + // + // exclusive_scan + // + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + exclusive_scan(InputIterator first, InputIterator last, Result const& result, T init, BinaryOperation binary_op) { + static_assert(sprout::is_forward_iterator::value, "Sorry, not implemented."); + return sprout::fit::detail::exclusive_scan_impl(first, last, result, init, binary_op, sprout::internal_begin_offset(result)); + } + } // namespace fit +} // namespace sprout + +#endif // #ifndef SPROUT_NUMERIC_FIT_EXCLUSIVE_SCAN_HPP diff --git a/sprout/numeric/fit/inclusive_scan.hpp b/sprout/numeric/fit/inclusive_scan.hpp new file mode 100644 index 00000000..ac05543a --- /dev/null +++ b/sprout/numeric/fit/inclusive_scan.hpp @@ -0,0 +1,102 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_NUMERIC_FIT_INCLUSIVE_SCAN_HPP +#define SPROUT_NUMERIC_FIT_INCLUSIVE_SCAN_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace fit { + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + inclusive_scan_impl( + InputIterator const& first, InputIterator const& last, Result const& result, + typename sprout::container_traits::difference_type offset + ) + { + return sprout::sub_copy( + sprout::get_internal(sprout::fixed::inclusive_scan(first, last, result)), + offset, + offset + sprout::fit_size(result, sprout::distance(first, last)) + ); + } + } // namespace detail + // + // inclusive_scan + // + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last, Result const& result) { + static_assert(sprout::is_forward_iterator::value, "Sorry, not implemented."); + return sprout::fit::detail::inclusive_scan_impl(first, last, result, sprout::internal_begin_offset(result)); + } + + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + inclusive_scan_impl( + InputIterator const& first, InputIterator const& last, Result const& result, BinaryOperation binary_op, + typename sprout::container_traits::difference_type offset + ) + { + typedef typename std::iterator_traits::difference_type diff_type; + return sprout::sub_copy( + sprout::get_internal(sprout::fixed::inclusive_scan(first, last, result, binary_op)), + offset, + offset + NS_SSCRISK_CEL_OR_SPROUT::min(sprout::distance(first, last), sprout::size(result)) + ); + } + } // namespace detail + // + // inclusive_scan + // + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last, Result const& result, BinaryOperation binary_op) { + static_assert(sprout::is_forward_iterator::value, "Sorry, not implemented."); + return sprout::fit::detail::inclusive_scan_impl(first, last, result, binary_op, sprout::internal_begin_offset(result)); + } + + namespace detail { + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + inclusive_scan_impl( + InputIterator const& first, InputIterator const& last, Result const& result, BinaryOperation binary_op, T init, + typename sprout::container_traits::difference_type offset + ) + { + typedef typename std::iterator_traits::difference_type diff_type; + return sprout::sub_copy( + sprout::get_internal(sprout::fixed::inclusive_scan(first, last, result, binary_op, init)), + offset, + offset + NS_SSCRISK_CEL_OR_SPROUT::min(sprout::distance(first, last) + 1, sprout::size(result)) + ); + } + } // namespace detail + // + // inclusive_scan + // + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last, Result const& result, BinaryOperation binary_op, T init) { + static_assert(sprout::is_forward_iterator::value, "Sorry, not implemented."); + return sprout::fit::detail::inclusive_scan_impl(first, last, result, binary_op, init, sprout::internal_begin_offset(result)); + } + } // namespace fit +} // namespace sprout + +#endif // #ifndef SPROUT_NUMERIC_FIT_INCLUSIVE_SCAN_HPP diff --git a/sprout/numeric/fixed.hpp b/sprout/numeric/fixed.hpp index ddf953a4..017bd453 100644 --- a/sprout/numeric/fixed.hpp +++ b/sprout/numeric/fixed.hpp @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include diff --git a/sprout/numeric/fixed/exclusive_scan.hpp b/sprout/numeric/fixed/exclusive_scan.hpp new file mode 100644 index 00000000..400df854 --- /dev/null +++ b/sprout/numeric/fixed/exclusive_scan.hpp @@ -0,0 +1,229 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_NUMERIC_FIXED_EXCLUSIVE_SCAN_HPP +#define SPROUT_NUMERIC_FIXED_EXCLUSIVE_SCAN_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace fixed { + namespace detail { + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size == sizeof...(Args) + 1, + typename sprout::fixed::results::algorithm::type + >::type + exclusive_scan_impl_1( + InputIterator const&, InputIterator const&, Result const& result, + typename sprout::container_traits::size_type, + typename sprout::container_traits::value_type const& value, + typename sprout::container_traits::value_type const& temp, + Args const&... args + ) + { + return sprout::remake(result, sprout::size(result), args..., value); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size != sizeof...(Args) + 1, + typename sprout::fixed::results::algorithm::type + >::type + exclusive_scan_impl_1( + InputIterator const& first, InputIterator const& last, Result const& result, + typename sprout::container_traits::size_type size, + typename sprout::container_traits::value_type const& value, + typename sprout::container_traits::value_type const& temp, + Args const&... args + ) + { + return first != last && sizeof...(Args) + 1 < size + ? exclusive_scan_impl_1(sprout::next(first), last, result, size, value + temp, *first, args..., value) + : sprout::detail::container_complate(result, args..., value) + ; + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size == 0, + typename sprout::fixed::results::algorithm::type + >::type + exclusive_scan_impl( + InputIterator, InputIterator, Result const& result, T, + typename sprout::container_traits::size_type + ) + { + return sprout::detail::container_complate(result); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size == 1, + typename sprout::fixed::results::algorithm::type + >::type + exclusive_scan_impl( + InputIterator, InputIterator, Result const& result, T init, + typename sprout::container_traits::size_type + ) + { + return sprout::detail::container_complate(result, init); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + (sprout::container_traits::static_size > 1), + typename sprout::fixed::results::algorithm::type + >::type + exclusive_scan_impl( + InputIterator const& first, InputIterator const& last, Result const& result, T init, + typename sprout::container_traits::size_type size + ) + { + return first != last + ? exclusive_scan_impl_1(sprout::next(first), last, result, size, init, *first) + : sprout::detail::container_complate(result, init) + ; + } + } // namespace detail + // + // exclusive_scan + // + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + exclusive_scan(InputIterator first, InputIterator last, Result const& result, T init) { + return sprout::fixed::detail::exclusive_scan_impl(first, last, result, init, sprout::size(result)); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + exclusive_scan(InputIterator first, InputIterator last, T init) { + return sprout::fixed::exclusive_scan(first, last, sprout::pit(), init); + } + + namespace detail { + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size == sizeof...(Args) + 1, + typename sprout::fixed::results::algorithm::type + >::type + exclusive_scan_impl_1( + InputIterator const&, InputIterator const&, Result const& result, BinaryOperation, + typename sprout::container_traits::size_type, + typename sprout::container_traits::value_type const& value, + typename sprout::container_traits::value_type const& temp, + Args const&... args + ) + { + return sprout::remake(result, sprout::size(result), args..., value); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size != sizeof...(Args) + 1, + typename sprout::fixed::results::algorithm::type + >::type + exclusive_scan_impl_1( + InputIterator const& first, InputIterator const& last, Result const& result, BinaryOperation binary_op, + typename sprout::container_traits::size_type size, + typename sprout::container_traits::value_type const& value, + typename sprout::container_traits::value_type const& temp, + Args const&... args + ) + { + return first != last && sizeof...(Args) + 1 < size + ? exclusive_scan_impl_1(sprout::next(first), last, result, binary_op, size, binary_op(value, temp), *first, args..., value) + : sprout::detail::container_complate(result, args..., value) + ; + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size == 0, + typename sprout::fixed::results::algorithm::type + >::type + exclusive_scan_impl( + InputIterator, InputIterator, Result const& result, T, BinaryOperation, + typename sprout::container_traits::size_type + ) + { + return sprout::detail::container_complate(result); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size == 1, + typename sprout::fixed::results::algorithm::type + >::type + exclusive_scan_impl( + InputIterator, InputIterator, Result const& result, T init, BinaryOperation, + typename sprout::container_traits::size_type + ) + { + return sprout::detail::container_complate(result, init); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + (sprout::container_traits::static_size > 1), + typename sprout::fixed::results::algorithm::type + >::type + exclusive_scan_impl( + InputIterator const& first, InputIterator const& last, Result const& result, T init, BinaryOperation binary_op, + typename sprout::container_traits::size_type size + ) + { + return first != last + ? exclusive_scan_impl_1(sprout::next(first), last, result, binary_op, size, init, *first) + : sprout::detail::container_complate(result, init) + ; + } + } // namespace detail + // + // exclusive_scan + // + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + exclusive_scan(InputIterator first, InputIterator last, Result const& result, T init, BinaryOperation binary_op) { + return sprout::fixed::detail::exclusive_scan_impl(first, last, result, init, binary_op, sprout::size(result)); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + exclusive_scan(InputIterator first, InputIterator last, T init, BinaryOperation binary_op) { + return sprout::fixed::exclusive_scan(first, last, sprout::pit(), init, binary_op); + } + } // namespace fixed + + template< + typename InputIterator, typename Result, typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + exclusive_scan(InputIterator first, InputIterator last, Result const& result, T init) { + return sprout::fixed::exclusive_scan(first, last, result, init); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + exclusive_scan(InputIterator first, InputIterator last, T init) { + return sprout::fixed::exclusive_scan(first, last, init); + } + + template< + typename InputIterator, typename Result, typename T, typename BinaryOperation, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + exclusive_scan(InputIterator first, InputIterator last, Result const& result, T init, BinaryOperation binary_op) { + return sprout::fixed::exclusive_scan(first, last, result, init, binary_op); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + exclusive_scan(InputIterator first, InputIterator last, T init, BinaryOperation binary_op) { + return sprout::fixed::exclusive_scan(first, last, init, binary_op); + } +} // namespace sprout + +#endif // #ifndef SPROUT_NUMERIC_FIXED_EXCLUSIVE_SCAN_HPP diff --git a/sprout/numeric/fixed/inclusive_scan.hpp b/sprout/numeric/fixed/inclusive_scan.hpp new file mode 100644 index 00000000..b247d036 --- /dev/null +++ b/sprout/numeric/fixed/inclusive_scan.hpp @@ -0,0 +1,147 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_NUMERIC_FIXED_INCLUSIVE_SCAN_HPP +#define SPROUT_NUMERIC_FIXED_INCLUSIVE_SCAN_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace fixed { + // + // inclusive_scan + // + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last, Result const& result) { + return sprout::fixed::partial_sum(first, last, result); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last) { + return sprout::fixed::partial_sum(first, last); + } + + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last, Result const& result, BinaryOperation binary_op) { + return sprout::fixed::partial_sum(first, last, result, binary_op); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last, BinaryOperation binary_op) { + return sprout::fixed::partial_sum(first, last, binary_op); + } + + namespace detail { + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size == 0, + typename sprout::fixed::results::algorithm::type + >::type + inclusive_scan_impl( + InputIterator, InputIterator, Result const& result, BinaryOperation, T, + typename sprout::container_traits::size_type + ) + { + return sprout::remake(result, sprout::size(result)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::container_traits::static_size == 1, + typename sprout::fixed::results::algorithm::type + >::type + inclusive_scan_impl( + InputIterator, InputIterator, Result const& result, BinaryOperation, T init, + typename sprout::container_traits::size_type + ) + { + return sprout::remake(result, sprout::size(result), init); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + (sprout::container_traits::static_size > 1), + typename sprout::fixed::results::algorithm::type + >::type + inclusive_scan_impl( + InputIterator const& first, InputIterator const& last, Result const& result, BinaryOperation binary_op, T init, + typename sprout::container_traits::size_type size + ) + { + return first != last + ? partial_sum_impl_1(first, last, result, binary_op, size, init) + : sprout::detail::container_complate(result, init) + ; + } + } // namespace detail + // + // inclusive_scan + // + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last, Result const& result, BinaryOperation binary_op, T init) { + return sprout::fixed::detail::inclusive_scan_impl(first, last, result, binary_op, init, sprout::size(result)); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last, BinaryOperation binary_op, T init) { + return sprout::fixed::inclusive_scan(first, last, sprout::pit(), binary_op, init); + } + } // namespace fixed + + template< + typename InputIterator, typename Result, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last, Result const& result) { + return sprout::fixed::inclusive_scan(first, last, result); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last) { + return sprout::fixed::inclusive_scan(first, last); + } + + template< + typename InputIterator, typename Result, typename BinaryOperation, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last, Result const& result, BinaryOperation binary_op) { + return sprout::fixed::inclusive_scan(first, last, result, binary_op); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last, BinaryOperation binary_op) { + return sprout::fixed::inclusive_scan(first, last, binary_op); + } + + template< + typename InputIterator, typename Result, typename BinaryOperation, typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last, Result const& result, BinaryOperation binary_op, T init) { + return sprout::fixed::inclusive_scan(first, last, result, binary_op, init); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputIterator first, InputIterator last, BinaryOperation binary_op, T init) { + return sprout::fixed::inclusive_scan(first, last, binary_op, init); + } +} // namespace sprout + +#endif // #ifndef SPROUT_NUMERIC_FIXED_INCLUSIVE_SCAN_HPP diff --git a/sprout/numeric/inclusive_scan.hpp b/sprout/numeric/inclusive_scan.hpp new file mode 100644 index 00000000..71878889 --- /dev/null +++ b/sprout/numeric/inclusive_scan.hpp @@ -0,0 +1,16 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_NUMERIC_INCLUSIVE_SCAN_HPP +#define SPROUT_NUMERIC_INCLUSIVE_SCAN_HPP + +#include +#include +#include +#include + +#endif // #ifndef SPROUT_NUMERIC_INCLUSIVE_SCAN_HPP diff --git a/sprout/numeric/iota.hpp b/sprout/numeric/iota.hpp index 7c53e6de..4059fbd6 100644 --- a/sprout/numeric/iota.hpp +++ b/sprout/numeric/iota.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_NUMERIC_IOTA_HPP diff --git a/sprout/numeric/non_modifying.hpp b/sprout/numeric/non_modifying.hpp index 927adcaa..1dff6adc 100644 --- a/sprout/numeric/non_modifying.hpp +++ b/sprout/numeric/non_modifying.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #endif // #ifndef SPROUT_NUMERIC_NON_MODIFYIING_HPP diff --git a/sprout/numeric/partial_sum.hpp b/sprout/numeric/partial_sum.hpp index 4673a488..30a2fe1b 100644 --- a/sprout/numeric/partial_sum.hpp +++ b/sprout/numeric/partial_sum.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_NUMERIC_PARTIAL_SUM_HPP diff --git a/sprout/numeric/reduce.hpp b/sprout/numeric/reduce.hpp new file mode 100644 index 00000000..f6db96fc --- /dev/null +++ b/sprout/numeric/reduce.hpp @@ -0,0 +1,42 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_NUMERIC_REDUCE_HPP +#define SPROUT_NUMERIC_REDUCE_HPP + +#include +#include +#include +#include + +namespace sprout { + // + // reduce + // + // recursion depth: + // O(log N) + // + template + inline SPROUT_CONSTEXPR typename std::iterator_traits::value_type + reduce(InputIterator first, InputIterator last) { + return sprout::accumulate(first, last, typename std::iterator_traits::value_type()); + } + + template + inline SPROUT_CONSTEXPR T + reduce(InputIterator first, InputIterator last, T init) { + return sprout::accumulate(first, last, init); + } + + template + inline SPROUT_CONSTEXPR T + reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op) { + return sprout::accumulate(first, last, init, binary_op); + } +} // namespace sprout + +#endif // #ifndef SPROUT_NUMERIC_REDUCE_HPP diff --git a/sprout/range/numeric/accumulate.hpp b/sprout/range/numeric/accumulate.hpp index 5ccfe0ca..c3893cf6 100644 --- a/sprout/range/numeric/accumulate.hpp +++ b/sprout/range/numeric/accumulate.hpp @@ -9,10 +9,12 @@ #define SPROUT_RANGE_NUMERIC_ACCUMLATE_HPP #include +#include #include namespace sprout { namespace range { + // 26.7.2 Accumulate template inline SPROUT_CONSTEXPR T diff --git a/sprout/range/numeric/cxx14.hpp b/sprout/range/numeric/cxx14.hpp index adb8d38c..38c9df8f 100644 --- a/sprout/range/numeric/cxx14.hpp +++ b/sprout/range/numeric/cxx14.hpp @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include diff --git a/sprout/range/numeric/cxx14/exclusive_scan.hpp b/sprout/range/numeric/cxx14/exclusive_scan.hpp new file mode 100644 index 00000000..4c0bb4d8 --- /dev/null +++ b/sprout/range/numeric/cxx14/exclusive_scan.hpp @@ -0,0 +1,42 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_RANGE_NUMERIC_CXX14_EXCLUSIVE_SCAN_HPP +#define SPROUT_RANGE_NUMERIC_CXX14_EXCLUSIVE_SCAN_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // + // exclusive_scan + // + template< + typename InputRange, typename OutputIterator, typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR OutputIterator + exclusive_scan(InputRange const& rng, OutputIterator result, T init) { + return sprout::exclusive_scan(sprout::begin(rng), sprout::end(rng), result, init); + } + template< + typename InputRange, typename OutputIterator, typename T, typename BinaryOperation, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR OutputIterator + exclusive_scan(InputRange const& rng, OutputIterator result, T init, BinaryOperation binary_op) { + return sprout::exclusive_scan(sprout::begin(rng), sprout::end(rng), result, init, binary_op); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_NUMERIC_CXX14_EXCLUSIVE_SCAN_HPP diff --git a/sprout/range/numeric/cxx14/inclusive_scan.hpp b/sprout/range/numeric/cxx14/inclusive_scan.hpp new file mode 100644 index 00000000..ee7ab3ad --- /dev/null +++ b/sprout/range/numeric/cxx14/inclusive_scan.hpp @@ -0,0 +1,50 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_RANGE_NUMERIC_CXX14_INCLUSIVE_SCAN_HPP +#define SPROUT_RANGE_NUMERIC_CXX14_INCLUSIVE_SCAN_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // + // inclusive_scan + // + template< + typename InputRange, typename OutputIterator, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR OutputIterator + inclusive_scan(InputRange const& rng, OutputIterator result) { + return sprout::inclusive_scan(sprout::begin(rng), sprout::end(rng), result); + } + template< + typename InputRange, typename OutputIterator, typename BinaryOperation, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR OutputIterator + inclusive_scan(InputRange const& rng, OutputIterator result, BinaryOperation binary_op) { + return sprout::inclusive_scan(sprout::begin(rng), sprout::end(rng), result, binary_op); + } + template< + typename InputRange, typename OutputIterator, typename BinaryOperation, typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR OutputIterator + inclusive_scan(InputRange const& rng, OutputIterator result, BinaryOperation binary_op, T init) { + return sprout::inclusive_scan(sprout::begin(rng), sprout::end(rng), result, binary_op, init); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_NUMERIC_CXX14_INCLUSIVE_SCAN_HPP diff --git a/sprout/range/numeric/exclusive_scan.hpp b/sprout/range/numeric/exclusive_scan.hpp new file mode 100644 index 00000000..a17f08d3 --- /dev/null +++ b/sprout/range/numeric/exclusive_scan.hpp @@ -0,0 +1,15 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_RANGE_NUMERIC_EXCLUSIVE_SCAN_HPP +#define SPROUT_RANGE_NUMERIC_EXCLUSIVE_SCAN_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_RANGE_NUMERIC_EXCLUSIVE_SCAN_HPP diff --git a/sprout/range/numeric/fit.hpp b/sprout/range/numeric/fit.hpp index 6a997bb8..93c07c5c 100644 --- a/sprout/range/numeric/fit.hpp +++ b/sprout/range/numeric/fit.hpp @@ -10,6 +10,8 @@ #include #include +#include +#include #include #endif // #ifndef SPROUT_RANGE_NUMERIC_FIT_HPP diff --git a/sprout/range/numeric/fit/exclusive_scan.hpp b/sprout/range/numeric/fit/exclusive_scan.hpp new file mode 100644 index 00000000..145c8102 --- /dev/null +++ b/sprout/range/numeric/fit/exclusive_scan.hpp @@ -0,0 +1,48 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_RANGE_NUMERIC_FIT_EXCLUSIVE_SCAN_HPP +#define SPROUT_RANGE_NUMERIC_FIT_EXCLUSIVE_SCAN_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + namespace fit { + // + // exclusive_scan + // + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + exclusive_scan(InputRange const& rng, Result const& result, T init) { + return sprout::fit::exclusive_scan(sprout::begin(rng), sprout::end(rng), result, init); + } + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + exclusive_scan(InputRange const& rng, Result const& result, T init, BinaryOperation binary_op) { + return sprout::fit::exclusive_scan(sprout::begin(rng), sprout::end(rng), result, init, binary_op); + } + + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + exclusive_scan(InputRange const& rng, T init) { + return sprout::fit::exclusive_scan(sprout::begin(rng), sprout::end(rng), init); + } + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + exclusive_scan(InputRange const& rng, T init, BinaryOperation binary_op) { + return sprout::fit::exclusive_scan(sprout::begin(rng), sprout::end(rng), init, binary_op); + } + } // namespace fit + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_NUMERIC_FIT_EXCLUSIVE_SCAN_HPP diff --git a/sprout/range/numeric/fit/inclusive_scan.hpp b/sprout/range/numeric/fit/inclusive_scan.hpp new file mode 100644 index 00000000..be1f7072 --- /dev/null +++ b/sprout/range/numeric/fit/inclusive_scan.hpp @@ -0,0 +1,58 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_RANGE_NUMERIC_FIT_INCLUSIVE_SCAN_HPP +#define SPROUT_RANGE_NUMERIC_FIT_INCLUSIVE_SCAN_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + namespace fit { + // + // inclusive_scan + // + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + inclusive_scan(InputRange const& rng, Result const& result) { + return sprout::fit::inclusive_scan(sprout::begin(rng), sprout::end(rng), result); + } + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + inclusive_scan(InputRange const& rng, Result const& result, BinaryOperation binary_op) { + return sprout::fit::inclusive_scan(sprout::begin(rng), sprout::end(rng), result, binary_op); + } + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + inclusive_scan(InputRange const& rng, Result const& result, BinaryOperation binary_op, T init) { + return sprout::fit::inclusive_scan(sprout::begin(rng), sprout::end(rng), result, binary_op, init); + } + + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + inclusive_scan(InputRange const& rng) { + return sprout::fit::inclusive_scan(sprout::begin(rng), sprout::end(rng)); + } + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + inclusive_scan(InputRange const& rng, BinaryOperation binary_op) { + return sprout::fit::inclusive_scan(sprout::begin(rng), sprout::end(rng), binary_op); + } + template + inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm::type + inclusive_scan(InputRange const& rng, BinaryOperation binary_op, T init) { + return sprout::fit::inclusive_scan(sprout::begin(rng), sprout::end(rng), binary_op, init); + } + } // namespace fit + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_NUMERIC_FIT_INCLUSIVE_SCAN_HPP diff --git a/sprout/range/numeric/fixed.hpp b/sprout/range/numeric/fixed.hpp index cfa71bcf..914d1d2e 100644 --- a/sprout/range/numeric/fixed.hpp +++ b/sprout/range/numeric/fixed.hpp @@ -10,6 +10,8 @@ #include #include +#include +#include #include #endif // #ifndef SPROUT_RANGE_NUMERIC_FIXED_HPP diff --git a/sprout/range/numeric/fixed/exclusive_scan.hpp b/sprout/range/numeric/fixed/exclusive_scan.hpp new file mode 100644 index 00000000..16ddd617 --- /dev/null +++ b/sprout/range/numeric/fixed/exclusive_scan.hpp @@ -0,0 +1,58 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_RANGE_NUMERIC_FIXED_EXCLUSIVE_SCAN_HPP +#define SPROUT_RANGE_NUMERIC_FIXED_EXCLUSIVE_SCAN_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + namespace fixed { + // + // exclusive_scan + // + template< + typename InputRange, typename Result, typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + exclusive_scan(InputRange const& rng, Result const& result, T init) { + return sprout::fixed::exclusive_scan(sprout::begin(rng), sprout::end(rng), result, init); + } + template< + typename InputRange, typename Result, typename T, typename BinaryOperation, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + exclusive_scan(InputRange const& rng, Result const& result, T init, BinaryOperation binary_op) { + return sprout::fixed::exclusive_scan(sprout::begin(rng), sprout::end(rng), result, init, binary_op); + } + + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + exclusive_scan(InputRange const& rng, T init) { + return sprout::fixed::exclusive_scan(sprout::begin(rng), sprout::end(rng), init); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + exclusive_scan(InputRange const& rng, T init, BinaryOperation binary_op) { + return sprout::fixed::exclusive_scan(sprout::begin(rng), sprout::end(rng), init, binary_op); + } + } // namespace fixed + + using sprout::range::fixed::exclusive_scan; + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_NUMERIC_FIXED_EXCLUSIVE_SCAN_HPP diff --git a/sprout/range/numeric/fixed/inclusive_scan.hpp b/sprout/range/numeric/fixed/inclusive_scan.hpp new file mode 100644 index 00000000..35f677fd --- /dev/null +++ b/sprout/range/numeric/fixed/inclusive_scan.hpp @@ -0,0 +1,71 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_RANGE_NUMERIC_FIXED_INCLUSIVE_SCAN_HPP +#define SPROUT_RANGE_NUMERIC_FIXED_INCLUSIVE_SCAN_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + namespace fixed { + // + // inclusive_scan + // + template< + typename InputRange, typename Result, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputRange const& rng, Result const& result) { + return sprout::fixed::inclusive_scan(sprout::begin(rng), sprout::end(rng), result); + } + template< + typename InputRange, typename Result, typename BinaryOperation, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputRange const& rng, Result const& result, BinaryOperation binary_op) { + return sprout::fixed::inclusive_scan(sprout::begin(rng), sprout::end(rng), result, binary_op); + } + template< + typename InputRange, typename Result, typename BinaryOperation, typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputRange const& rng, Result const& result, BinaryOperation binary_op, T init) { + return sprout::fixed::inclusive_scan(sprout::begin(rng), sprout::end(rng), result, binary_op, init); + } + + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputRange const& rng) { + return sprout::fixed::inclusive_scan(sprout::begin(rng), sprout::end(rng)); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputRange const& rng, BinaryOperation binary_op) { + return sprout::fixed::inclusive_scan(sprout::begin(rng), sprout::end(rng), binary_op); + } + template + inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm::type + inclusive_scan(InputRange const& rng, BinaryOperation binary_op, T init) { + return sprout::fixed::inclusive_scan(sprout::begin(rng), sprout::end(rng), binary_op, init); + } + } // namespace fixed + + using sprout::range::fixed::inclusive_scan; + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_NUMERIC_FIXED_INCLUSIVE_SCAN_HPP diff --git a/sprout/range/numeric/inclusive_scan.hpp b/sprout/range/numeric/inclusive_scan.hpp new file mode 100644 index 00000000..30b9f159 --- /dev/null +++ b/sprout/range/numeric/inclusive_scan.hpp @@ -0,0 +1,15 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_RANGE_NUMERIC_INCLUSIVE_SCAN_HPP +#define SPROUT_RANGE_NUMERIC_INCLUSIVE_SCAN_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_RANGE_NUMERIC_INCLUSIVE_SCAN_HPP diff --git a/sprout/range/numeric/inner_product.hpp b/sprout/range/numeric/inner_product.hpp index 07bbf413..4ab56821 100644 --- a/sprout/range/numeric/inner_product.hpp +++ b/sprout/range/numeric/inner_product.hpp @@ -9,10 +9,12 @@ #define SPROUT_RANGE_NUMERIC_INNER_PRODUCT_HPP #include +#include #include namespace sprout { namespace range { + // 26.7.3 Inner product template inline SPROUT_CONSTEXPR T diff --git a/sprout/range/numeric/non_modifying.hpp b/sprout/range/numeric/non_modifying.hpp index 1d94c876..ee3f5bda 100644 --- a/sprout/range/numeric/non_modifying.hpp +++ b/sprout/range/numeric/non_modifying.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #endif // #ifndef SPROUT_RANGE_NUMERIC_NON_MODIFYIING_HPP diff --git a/sprout/range/numeric/reduce.hpp b/sprout/range/numeric/reduce.hpp new file mode 100644 index 00000000..15672e00 --- /dev/null +++ b/sprout/range/numeric/reduce.hpp @@ -0,0 +1,41 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_RANGE_NUMERIC_REDUCE_HPP +#define SPROUT_RANGE_NUMERIC_REDUCE_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + + // 29.8.3 Reduce + template + inline SPROUT_CONSTEXPR T + reduce(InputRange const& range, T init, BinaryOperation binary_op) { + return sprout::reduce(sprout::begin(range), sprout::end(range), init, binary_op); + } + + template + inline SPROUT_CONSTEXPR T + reduce(InputRange const& range, T init) { + return sprout::reduce(sprout::begin(range), sprout::end(range), init); + } + + template + inline SPROUT_CONSTEXPR typename std::iterator_traits::iterator>::value_type + reduce(InputRange const& range) { + return sprout::reduce(sprout::begin(range), sprout::end(range)); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_NUMERIC_REDUCE_HPP diff --git a/sprout/sub_array/container.hpp b/sprout/sub_array/container.hpp index 8117dbe1..3fcf9eb4 100644 --- a/sprout/sub_array/container.hpp +++ b/sprout/sub_array/container.hpp @@ -85,7 +85,7 @@ namespace sprout { public: typedef sprout::sub_array< typename sprout::container_transform_traits< - typename std::remove_reference::type + typename sprout::container_construct_traits::copied_type >::template rebind_size::type > type; }; @@ -94,7 +94,7 @@ namespace sprout { public: typedef sprout::sub_array< typename sprout::container_transform_traits< - typename std::remove_reference::type + typename sprout::container_construct_traits::copied_type >::template rebind_type::type > type; }; diff --git a/testspr/trace.hpp b/testspr/trace.hpp index 6fa195b7..5e883e71 100644 --- a/testspr/trace.hpp +++ b/testspr/trace.hpp @@ -155,14 +155,18 @@ namespace testspr { SPROUT_NON_CONSTEXPR comparable_function(function_type const& f) : func_(f) {} - SPROUT_NON_CONSTEXPR bool operator()(trace_stack const& t) { + SPROUT_NON_CONSTEXPR bool operator()(trace_stack const& t) const { return func_(t); } - SPROUT_NON_CONSTEXPR bool operator==(function_type const& rhs) { - return func_.target_type() == rhs.target_type(); + SPROUT_NON_CONSTEXPR bool operator==(function_type const& rhs) const { + return func_ == nullptr ? rhs == nullptr + : rhs == nullptr ? false + : func_.target_type() == rhs.target_type() + && func_.target() == rhs.target() + ; } - SPROUT_NON_CONSTEXPR bool operator!=(function_type const& rhs) { - return func_.target_type() != rhs.target_type(); + SPROUT_NON_CONSTEXPR bool operator!=(function_type const& rhs) const { + return !(*this == rhs); } }; private: