From de41f5c880f86fe1173b7eccab419605abc92c6a Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 13 Oct 2012 12:49:23 +0900 Subject: [PATCH] add algorithm one_of, all_of_equal, any_of_equal, none_of_equal, one_of_equal, is_increasing, is_decreasing, is_strictly_increasing, is_strictly_decreasing --- sprout/algorithm/all_of_equal.hpp | 20 ++++++++++++ sprout/algorithm/any_of_equal.hpp | 20 ++++++++++++ sprout/algorithm/is_decreasing.hpp | 23 +++++++++++++ sprout/algorithm/is_increasing.hpp | 23 +++++++++++++ sprout/algorithm/is_strictly_decreasing.hpp | 23 +++++++++++++ sprout/algorithm/is_strictly_increasing.hpp | 23 +++++++++++++ sprout/algorithm/non_modifying.hpp | 9 ++++++ sprout/algorithm/none_of_equal.hpp | 20 ++++++++++++ sprout/algorithm/one_of.hpp | 31 ++++++++++++++++++ sprout/algorithm/one_of_equal.hpp | 32 +++++++++++++++++++ sprout/bitset/bitset.hpp | 4 +-- sprout/range/algorithm/all_of_equal.hpp | 21 ++++++++++++ sprout/range/algorithm/any_of_equal.hpp | 21 ++++++++++++ sprout/range/algorithm/is_decreasing.hpp | 21 ++++++++++++ sprout/range/algorithm/is_increasing.hpp | 21 ++++++++++++ .../algorithm/is_strictly_decreasing.hpp | 21 ++++++++++++ .../algorithm/is_strictly_increasing.hpp | 21 ++++++++++++ sprout/range/algorithm/non_modifying.hpp | 9 ++++++ sprout/range/algorithm/none_of_equal.hpp | 21 ++++++++++++ sprout/range/algorithm/one_of.hpp | 21 ++++++++++++ sprout/range/algorithm/one_of_equal.hpp | 21 ++++++++++++ sprout/range/numeric/fixed/partial_sum.hpp | 2 +- 22 files changed, 425 insertions(+), 3 deletions(-) create mode 100644 sprout/algorithm/all_of_equal.hpp create mode 100644 sprout/algorithm/any_of_equal.hpp create mode 100644 sprout/algorithm/is_decreasing.hpp create mode 100644 sprout/algorithm/is_increasing.hpp create mode 100644 sprout/algorithm/is_strictly_decreasing.hpp create mode 100644 sprout/algorithm/is_strictly_increasing.hpp create mode 100644 sprout/algorithm/none_of_equal.hpp create mode 100644 sprout/algorithm/one_of.hpp create mode 100644 sprout/algorithm/one_of_equal.hpp create mode 100644 sprout/range/algorithm/all_of_equal.hpp create mode 100644 sprout/range/algorithm/any_of_equal.hpp create mode 100644 sprout/range/algorithm/is_decreasing.hpp create mode 100644 sprout/range/algorithm/is_increasing.hpp create mode 100644 sprout/range/algorithm/is_strictly_decreasing.hpp create mode 100644 sprout/range/algorithm/is_strictly_increasing.hpp create mode 100644 sprout/range/algorithm/none_of_equal.hpp create mode 100644 sprout/range/algorithm/one_of.hpp create mode 100644 sprout/range/algorithm/one_of_equal.hpp diff --git a/sprout/algorithm/all_of_equal.hpp b/sprout/algorithm/all_of_equal.hpp new file mode 100644 index 00000000..79f4e131 --- /dev/null +++ b/sprout/algorithm/all_of_equal.hpp @@ -0,0 +1,20 @@ +#ifndef SPROUT_ALGORITHM_ALL_OF_EQUAL_HPP +#define SPROUT_ALGORITHM_ALL_OF_EQUAL_HPP + +#include +#include + +namespace sprout { + // + // all_of_equal + // + template + inline SPROUT_CONSTEXPR bool + all_of_equal(InputIterator first, InputIterator last, T const& value) { + return first == last ? true + : *first == value && sprout::all_of_equal(sprout::next(first), last, value) + ; + } +} // namespace sprout + +#endif // #ifndef SPROUT_ALGORITHM_ALL_OF_EQUAL_HPP diff --git a/sprout/algorithm/any_of_equal.hpp b/sprout/algorithm/any_of_equal.hpp new file mode 100644 index 00000000..2bc6e03c --- /dev/null +++ b/sprout/algorithm/any_of_equal.hpp @@ -0,0 +1,20 @@ +#ifndef SPROUT_ALGORITHM_ANY_OF_EQUAL_HPP +#define SPROUT_ALGORITHM_ANY_OF_EQUAL_HPP + +#include +#include + +namespace sprout { + // + // any_of_equal + // + template + inline SPROUT_CONSTEXPR bool + any_of_equal(InputIterator first, InputIterator last, T const& value) { + return first == last ? false + : *first == value || sprout::any_of_equal(sprout::next(first), last, value) + ; + } +} // namespace sprout + +#endif // #ifndef SPROUT_ALGORITHM_ANY_OF_EQUAL_HPP diff --git a/sprout/algorithm/is_decreasing.hpp b/sprout/algorithm/is_decreasing.hpp new file mode 100644 index 00000000..87a094e0 --- /dev/null +++ b/sprout/algorithm/is_decreasing.hpp @@ -0,0 +1,23 @@ +#ifndef SPROUT_ALGORITHM_IS_DECREASING_HPP +#define SPROUT_ALGORITHM_IS_DECREASING_HPP + +#include +#include +#include +#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT + +namespace sprout { + // + // is_decreasing + // + template + inline SPROUT_CONSTEXPR bool + is_decreasing(ForwardIterator first, ForwardIterator last) { + return sprout::is_sorted( + first, last, + NS_SSCRISK_CEL_OR_SPROUT::greater::value_type>() + ); + } +} // namespace sprout + +#endif // #ifndef SPROUT_ALGORITHM_IS_DECREASING_HPP diff --git a/sprout/algorithm/is_increasing.hpp b/sprout/algorithm/is_increasing.hpp new file mode 100644 index 00000000..7f1506c9 --- /dev/null +++ b/sprout/algorithm/is_increasing.hpp @@ -0,0 +1,23 @@ +#ifndef SPROUT_ALGORITHM_IS_INCREASING_HPP +#define SPROUT_ALGORITHM_IS_INCREASING_HPP + +#include +#include +#include +#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT + +namespace sprout { + // + // is_increasing + // + template + inline SPROUT_CONSTEXPR bool + is_increasing(ForwardIterator first, ForwardIterator last) { + return sprout::is_sorted( + first, last, + NS_SSCRISK_CEL_OR_SPROUT::less::value_type>() + ); + } +} // namespace sprout + +#endif // #ifndef SPROUT_ALGORITHM_IS_INCREASING_HPP diff --git a/sprout/algorithm/is_strictly_decreasing.hpp b/sprout/algorithm/is_strictly_decreasing.hpp new file mode 100644 index 00000000..59a1f80d --- /dev/null +++ b/sprout/algorithm/is_strictly_decreasing.hpp @@ -0,0 +1,23 @@ +#ifndef SPROUT_ALGORITHM_IS_STRICTLY_DECREASING_HPP +#define SPROUT_ALGORITHM_IS_STRICTLY_DECREASING_HPP + +#include +#include +#include +#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT + +namespace sprout { + // + // is_strictly_decreasing + // + template + inline SPROUT_CONSTEXPR bool + is_strictly_decreasing(ForwardIterator first, ForwardIterator last) { + return sprout::is_sorted( + first, last, + NS_SSCRISK_CEL_OR_SPROUT::greater_equal::value_type>() + ); + } +} // namespace sprout + +#endif // #ifndef SPROUT_ALGORITHM_IS_STRICTLY_DECREASING_HPP diff --git a/sprout/algorithm/is_strictly_increasing.hpp b/sprout/algorithm/is_strictly_increasing.hpp new file mode 100644 index 00000000..331c1ca0 --- /dev/null +++ b/sprout/algorithm/is_strictly_increasing.hpp @@ -0,0 +1,23 @@ +#ifndef SPROUT_ALGORITHM_IS_STRICTLY_INCREASING_HPP +#define SPROUT_ALGORITHM_IS_STRICTLY_INCREASING_HPP + +#include +#include +#include +#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT + +namespace sprout { + // + // is_strictly_increasing + // + template + inline SPROUT_CONSTEXPR bool + is_strictly_increasing(ForwardIterator first, ForwardIterator last) { + return sprout::is_sorted( + first, last, + NS_SSCRISK_CEL_OR_SPROUT::less_equal::value_type>() + ); + } +} // namespace sprout + +#endif // #ifndef SPROUT_ALGORITHM_IS_STRICTLY_INCREASING_HPP diff --git a/sprout/algorithm/non_modifying.hpp b/sprout/algorithm/non_modifying.hpp index 322192a4..60a55d07 100644 --- a/sprout/algorithm/non_modifying.hpp +++ b/sprout/algorithm/non_modifying.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -36,5 +37,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #endif // #ifndef SPROUT_ALGORITHM_NON_MODIFYIING_HPP diff --git a/sprout/algorithm/none_of_equal.hpp b/sprout/algorithm/none_of_equal.hpp new file mode 100644 index 00000000..36c3b0ef --- /dev/null +++ b/sprout/algorithm/none_of_equal.hpp @@ -0,0 +1,20 @@ +#ifndef SPROUT_ALGORITHM_NONE_OF_EQUAL_HPP +#define SPROUT_ALGORITHM_NONE_OF_EQUAL_HPP + +#include +#include + +namespace sprout { + // + // none_of_equal + // + template + inline SPROUT_CONSTEXPR bool + none_of_equal(InputIterator first, InputIterator last, T const& value) { + return first == last ? true + : !(*first == value) && sprout::none_of_equal(sprout::next(first), last, value) + ; + } +} // namespace sprout + +#endif // #ifndef SPROUT_ALGORITHM_NONE_OF_EQUAL_HPP diff --git a/sprout/algorithm/one_of.hpp b/sprout/algorithm/one_of.hpp new file mode 100644 index 00000000..bbcb2fc0 --- /dev/null +++ b/sprout/algorithm/one_of.hpp @@ -0,0 +1,31 @@ +#ifndef SPROUT_ALGORITHM_ONE_OF_HPP +#define SPROUT_ALGORITHM_ONE_OF_HPP + +#include +#include +#include + +namespace sprout { + namespace detail { + template + inline SPROUT_CONSTEXPR bool + one_of_impl(InputIterator found, InputIterator last, Predicate pred) { + return found != last + && NS_SSCRISK_CEL_OR_SPROUT::none_of(sprout::next(found), last, pred) + ; + } + } // namespace detail + // + // one_of + // + template + inline SPROUT_CONSTEXPR bool + one_of(InputIterator first, InputIterator last, Predicate pred) { + return sprout::detail::one_of_impl( + sprout::find_if(first, last, pred), last, + pred + ); + } +} // namespace sprout + +#endif // #ifndef SPROUT_ALGORITHM_ONE_OF_HPP diff --git a/sprout/algorithm/one_of_equal.hpp b/sprout/algorithm/one_of_equal.hpp new file mode 100644 index 00000000..029d00cc --- /dev/null +++ b/sprout/algorithm/one_of_equal.hpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_ALGORITHM_ONE_OF_EQUAL_HPP +#define SPROUT_ALGORITHM_ONE_OF_EQUAL_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace detail { + template + inline SPROUT_CONSTEXPR bool + one_of_equal_impl(InputIterator found, InputIterator last, T const& value) { + return found != last + && sprout::none_of_equal(sprout::next(found), last, value) + ; + } + } // namespace detail + // + // one_of_equal + // + template + inline SPROUT_CONSTEXPR bool + one_of_equal(InputIterator first, InputIterator last, T const& value) { + return sprout::detail::one_of_equal_impl( + sprout::find(first, last, value), last, + value + ); + } +} // namespace sprout + +#endif // #ifndef SPROUT_ALGORITHM_ONE_OF_EQUAL_HPP diff --git a/sprout/bitset/bitset.hpp b/sprout/bitset/bitset.hpp index ede9e689..15e4614a 100644 --- a/sprout/bitset/bitset.hpp +++ b/sprout/bitset/bitset.hpp @@ -395,7 +395,7 @@ namespace sprout { } SPROUT_CONSTEXPR std::size_t do_count() const SPROUT_NOEXCEPT { - return NS_SSCRISK_CEL_OR_SPROUT::accumulate(begin(), end(),static_cast(0), count_op()); + return NS_SSCRISK_CEL_OR_SPROUT::accumulate(begin(), end(), static_cast(0), count_op()); } SPROUT_CONSTEXPR unsigned long @@ -1046,7 +1046,7 @@ namespace sprout { } template void - copy_to_string(std::basic_string& s) const { + copy_to_string(std::basic_string& s) const { copy_to_string(s, Char('0'), Char('1')); } diff --git a/sprout/range/algorithm/all_of_equal.hpp b/sprout/range/algorithm/all_of_equal.hpp new file mode 100644 index 00000000..1ab79d43 --- /dev/null +++ b/sprout/range/algorithm/all_of_equal.hpp @@ -0,0 +1,21 @@ +#ifndef SPROUT_RANGE_ALGORITHM_ALL_OF_EQUAL_HPP +#define SPROUT_RANGE_ALGORITHM_ALL_OF_EQUAL_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // + // all_of_equal + // + template + inline SPROUT_CONSTEXPR bool + all_of_equal(Range const& range, T const& value) { + return sprout::all_of_equal(sprout::begin(range), sprout::end(range), value); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_ALL_OF_EQUAL_HPP diff --git a/sprout/range/algorithm/any_of_equal.hpp b/sprout/range/algorithm/any_of_equal.hpp new file mode 100644 index 00000000..3c317c38 --- /dev/null +++ b/sprout/range/algorithm/any_of_equal.hpp @@ -0,0 +1,21 @@ +#ifndef SPROUT_RANGE_ALGORITHM_ALL_OF_EQUAL_HPP +#define SPROUT_RANGE_ALGORITHM_ALL_OF_EQUAL_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // + // any_of_equal + // + template + inline SPROUT_CONSTEXPR bool + any_of_equal(Range const& range, T const& value) { + return sprout::any_of_equal(sprout::begin(range), sprout::end(range), value); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_ALL_OF_EQUAL_HPP diff --git a/sprout/range/algorithm/is_decreasing.hpp b/sprout/range/algorithm/is_decreasing.hpp new file mode 100644 index 00000000..b939255f --- /dev/null +++ b/sprout/range/algorithm/is_decreasing.hpp @@ -0,0 +1,21 @@ +#ifndef SPROUT_RANGE_ALGORITHM_IS_DECREASING_HPP +#define SPROUT_RANGE_ALGORITHM_IS_DECREASING_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // + // is_decreasing + // + template + inline SPROUT_CONSTEXPR bool + is_decreasing(Range const& range) { + return sprout::is_decreasing(sprout::begin(range), sprout::end(range)); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_IS_DECREASING_HPP diff --git a/sprout/range/algorithm/is_increasing.hpp b/sprout/range/algorithm/is_increasing.hpp new file mode 100644 index 00000000..b34627b8 --- /dev/null +++ b/sprout/range/algorithm/is_increasing.hpp @@ -0,0 +1,21 @@ +#ifndef SPROUT_RANGE_ALGORITHM_IS_INCREASING_HPP +#define SPROUT_RANGE_ALGORITHM_IS_INCREASING_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // + // is_increasing + // + template + inline SPROUT_CONSTEXPR bool + is_increasing(Range const& range) { + return sprout::is_increasing(sprout::begin(range), sprout::end(range)); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_IS_INCREASING_HPP diff --git a/sprout/range/algorithm/is_strictly_decreasing.hpp b/sprout/range/algorithm/is_strictly_decreasing.hpp new file mode 100644 index 00000000..e03b6d37 --- /dev/null +++ b/sprout/range/algorithm/is_strictly_decreasing.hpp @@ -0,0 +1,21 @@ +#ifndef SPROUT_RANGE_ALGORITHM_IS_STRICTLY_DECREASING_HPP +#define SPROUT_RANGE_ALGORITHM_IS_STRICTLY_DECREASING_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // + // is_strictly_decreasing + // + template + inline SPROUT_CONSTEXPR bool + is_strictly_decreasing(Range const& range) { + return sprout::is_strictly_decreasing(sprout::begin(range), sprout::end(range)); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_IS_STRICTLY_DECREASING_HPP diff --git a/sprout/range/algorithm/is_strictly_increasing.hpp b/sprout/range/algorithm/is_strictly_increasing.hpp new file mode 100644 index 00000000..8cb1438c --- /dev/null +++ b/sprout/range/algorithm/is_strictly_increasing.hpp @@ -0,0 +1,21 @@ +#ifndef SPROUT_RANGE_ALGORITHM_IS_STRICTLY_INCREASING_HPP +#define SPROUT_RANGE_ALGORITHM_IS_STRICTLY_INCREASING_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // + // is_strictly_increasing + // + template + inline SPROUT_CONSTEXPR bool + is_strictly_increasing(Range const& range) { + return sprout::is_strictly_increasing(sprout::begin(range), sprout::end(range)); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_IS_STRICTLY_INCREASING_HPP diff --git a/sprout/range/algorithm/non_modifying.hpp b/sprout/range/algorithm/non_modifying.hpp index bb9f6330..e5fcd663 100644 --- a/sprout/range/algorithm/non_modifying.hpp +++ b/sprout/range/algorithm/non_modifying.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -33,5 +34,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #endif // #ifndef SPROUT_RANGE_ALGORITHM_NON_MODIFYIING_HPP diff --git a/sprout/range/algorithm/none_of_equal.hpp b/sprout/range/algorithm/none_of_equal.hpp new file mode 100644 index 00000000..bac4b847 --- /dev/null +++ b/sprout/range/algorithm/none_of_equal.hpp @@ -0,0 +1,21 @@ +#ifndef SPROUT_RANGE_ALGORITHM_NONE_OF_EQUAL_HPP +#define SPROUT_RANGE_ALGORITHM_NONE_OF_EQUAL_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // + // none_of_equal + // + template + inline SPROUT_CONSTEXPR bool + none_of_equal(Range const& range, T const& value) { + return sprout::none_of_equal(sprout::begin(range), sprout::end(range), value); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_NONE_OF_EQUAL_HPP diff --git a/sprout/range/algorithm/one_of.hpp b/sprout/range/algorithm/one_of.hpp new file mode 100644 index 00000000..68f602ad --- /dev/null +++ b/sprout/range/algorithm/one_of.hpp @@ -0,0 +1,21 @@ +#ifndef SPROUT_RANGE_ALGORITHM_ONE_OF_HPP +#define SPROUT_RANGE_ALGORITHM_ONE_OF_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // + // one_of + // + template + inline SPROUT_CONSTEXPR bool + one_of(Range const& range, Predicate pred) { + return sprout::one_of(sprout::begin(range), sprout::end(range), pred); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_ONE_OF_HPP diff --git a/sprout/range/algorithm/one_of_equal.hpp b/sprout/range/algorithm/one_of_equal.hpp new file mode 100644 index 00000000..e206c972 --- /dev/null +++ b/sprout/range/algorithm/one_of_equal.hpp @@ -0,0 +1,21 @@ +#ifndef SPROUT_RANGE_ALGORITHM_ONE_OF_EQUAL_HPP +#define SPROUT_RANGE_ALGORITHM_ONE_OF_EQUAL_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // + // one_of_equal + // + template + inline SPROUT_CONSTEXPR bool + one_of_equal(Range const& range, T const& value) { + return sprout::one_of_equal(sprout::begin(range), sprout::end(range), value); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_ONE_OF_EQUAL_HPP diff --git a/sprout/range/numeric/fixed/partial_sum.hpp b/sprout/range/numeric/fixed/partial_sum.hpp index 199552f3..29f94b1f 100644 --- a/sprout/range/numeric/fixed/partial_sum.hpp +++ b/sprout/range/numeric/fixed/partial_sum.hpp @@ -20,7 +20,7 @@ namespace sprout { } template inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm::type - partial_sum(Input const& input, Result const& result,BinaryOperation binary_op) { + partial_sum(Input const& input, Result const& result, BinaryOperation binary_op) { return sprout::fixed::partial_sum(sprout::begin(input), sprout::end(input), result, binary_op); } } // namespace fixed