From 0fa551beedd6d4da3884f049f4a1dafbbf1b7d85 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 5 Apr 2014 19:52:21 +0900 Subject: [PATCH] add c++14 constexpr range numeric algorithms --- sprout/range/numeric/cxx14.hpp | 16 +++++++ .../numeric/cxx14/adjacent_difference.hpp | 42 +++++++++++++++++++ sprout/range/numeric/cxx14/iota.hpp | 28 +++++++++++++ sprout/range/numeric/cxx14/partial_sum.hpp | 42 +++++++++++++++++++ sprout/range/numeric/modifying.hpp | 1 + 5 files changed, 129 insertions(+) create mode 100644 sprout/range/numeric/cxx14.hpp create mode 100644 sprout/range/numeric/cxx14/adjacent_difference.hpp create mode 100644 sprout/range/numeric/cxx14/iota.hpp create mode 100644 sprout/range/numeric/cxx14/partial_sum.hpp diff --git a/sprout/range/numeric/cxx14.hpp b/sprout/range/numeric/cxx14.hpp new file mode 100644 index 00000000..7d42ceb9 --- /dev/null +++ b/sprout/range/numeric/cxx14.hpp @@ -0,0 +1,16 @@ +/*============================================================================= + Copyright (c) 2011-2014 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_HPP +#define SPROUT_RANGE_NUMERIC_CXX14_HPP + +#include +#include +#include +#include + +#endif // #ifndef SPROUT_RANGE_NUMERIC_CXX14_HPP diff --git a/sprout/range/numeric/cxx14/adjacent_difference.hpp b/sprout/range/numeric/cxx14/adjacent_difference.hpp new file mode 100644 index 00000000..4b7ac4e1 --- /dev/null +++ b/sprout/range/numeric/cxx14/adjacent_difference.hpp @@ -0,0 +1,42 @@ +/*============================================================================= + Copyright (c) 2011-2014 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_ADJACENT_DIFFERENCE_HPP +#define SPROUT_RANGE_NUMERIC_CXX14_ADJACENT_DIFFERENCE_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // + // adjacent_difference + // + template< + typename InputRange, typename OutputIterator, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR OutputIterator + adjacent_difference(InputRange const& rng, OutputIterator result) { + return sprout::adjacent_difference(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 + adjacent_difference(InputRange const& rng, OutputIterator result, BinaryOperation binary_op) { + return sprout::adjacent_difference(sprout::begin(rng), sprout::end(rng), result, binary_op); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_NUMERIC_CXX14_ADJACENT_DIFFERENCE_HPP diff --git a/sprout/range/numeric/cxx14/iota.hpp b/sprout/range/numeric/cxx14/iota.hpp new file mode 100644 index 00000000..ca5201c0 --- /dev/null +++ b/sprout/range/numeric/cxx14/iota.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2011-2014 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_IOTA_HPP +#define SPROUT_RANGE_NUMERIC_CXX14_IOTA_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // + // iota + // + template + inline SPROUT_CXX14_CONSTEXPR void + iota(ForwardRange const& rng, T value) { + sprout::iota(sprout::begin(rng), sprout::end(rng), value); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_NUMERIC_CXX14_IOTA_HPP diff --git a/sprout/range/numeric/cxx14/partial_sum.hpp b/sprout/range/numeric/cxx14/partial_sum.hpp new file mode 100644 index 00000000..b6e5791d --- /dev/null +++ b/sprout/range/numeric/cxx14/partial_sum.hpp @@ -0,0 +1,42 @@ +/*============================================================================= + Copyright (c) 2011-2014 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_PARTIAL_SUM_HPP +#define SPROUT_RANGE_NUMERIC_CXX14_PARTIAL_SUM_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // + // partial_sum + // + template< + typename InputRange, typename OutputIterator, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR OutputIterator + partial_sum(InputRange const& rng, OutputIterator result) { + return sprout::partial_sum(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 + partial_sum(InputRange const& rng, OutputIterator result, BinaryOperation binary_op) { + return sprout::partial_sum(sprout::begin(rng), sprout::end(rng), result, binary_op); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_NUMERIC_CXX14_PARTIAL_SUM_HPP diff --git a/sprout/range/numeric/modifying.hpp b/sprout/range/numeric/modifying.hpp index b784b8ce..6291d55e 100644 --- a/sprout/range/numeric/modifying.hpp +++ b/sprout/range/numeric/modifying.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_RANGE_NUMERIC_MODIFYIING_HPP