1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

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

This commit is contained in:
bolero-MURAKAMI 2012-10-13 12:49:23 +09:00
parent 1ef528d204
commit de41f5c880
22 changed files with 425 additions and 3 deletions

View file

@ -0,0 +1,20 @@
#ifndef SPROUT_ALGORITHM_ALL_OF_EQUAL_HPP
#define SPROUT_ALGORITHM_ALL_OF_EQUAL_HPP
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
namespace sprout {
//
// all_of_equal
//
template<typename InputIterator, typename T>
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

View file

@ -0,0 +1,20 @@
#ifndef SPROUT_ALGORITHM_ANY_OF_EQUAL_HPP
#define SPROUT_ALGORITHM_ANY_OF_EQUAL_HPP
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
namespace sprout {
//
// any_of_equal
//
template<typename InputIterator, typename T>
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

View file

@ -0,0 +1,23 @@
#ifndef SPROUT_ALGORITHM_IS_DECREASING_HPP
#define SPROUT_ALGORITHM_IS_DECREASING_HPP
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/algorithm/is_sorted.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
namespace sprout {
//
// is_decreasing
//
template<typename ForwardIterator>
inline SPROUT_CONSTEXPR bool
is_decreasing(ForwardIterator first, ForwardIterator last) {
return sprout::is_sorted(
first, last,
NS_SSCRISK_CEL_OR_SPROUT::greater<typename std::iterator_traits<ForwardIterator>::value_type>()
);
}
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_IS_DECREASING_HPP

View file

@ -0,0 +1,23 @@
#ifndef SPROUT_ALGORITHM_IS_INCREASING_HPP
#define SPROUT_ALGORITHM_IS_INCREASING_HPP
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/algorithm/is_sorted.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
namespace sprout {
//
// is_increasing
//
template<typename ForwardIterator>
inline SPROUT_CONSTEXPR bool
is_increasing(ForwardIterator first, ForwardIterator last) {
return sprout::is_sorted(
first, last,
NS_SSCRISK_CEL_OR_SPROUT::less<typename std::iterator_traits<ForwardIterator>::value_type>()
);
}
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_IS_INCREASING_HPP

View file

@ -0,0 +1,23 @@
#ifndef SPROUT_ALGORITHM_IS_STRICTLY_DECREASING_HPP
#define SPROUT_ALGORITHM_IS_STRICTLY_DECREASING_HPP
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/algorithm/is_sorted.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
namespace sprout {
//
// is_strictly_decreasing
//
template<typename ForwardIterator>
inline SPROUT_CONSTEXPR bool
is_strictly_decreasing(ForwardIterator first, ForwardIterator last) {
return sprout::is_sorted(
first, last,
NS_SSCRISK_CEL_OR_SPROUT::greater_equal<typename std::iterator_traits<ForwardIterator>::value_type>()
);
}
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_IS_STRICTLY_DECREASING_HPP

View file

@ -0,0 +1,23 @@
#ifndef SPROUT_ALGORITHM_IS_STRICTLY_INCREASING_HPP
#define SPROUT_ALGORITHM_IS_STRICTLY_INCREASING_HPP
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/algorithm/is_sorted.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
namespace sprout {
//
// is_strictly_increasing
//
template<typename ForwardIterator>
inline SPROUT_CONSTEXPR bool
is_strictly_increasing(ForwardIterator first, ForwardIterator last) {
return sprout::is_sorted(
first, last,
NS_SSCRISK_CEL_OR_SPROUT::less_equal<typename std::iterator_traits<ForwardIterator>::value_type>()
);
}
} // namespace sprout
#endif // #ifndef SPROUT_ALGORITHM_IS_STRICTLY_INCREASING_HPP

View file

@ -5,6 +5,7 @@
#include <sprout/algorithm/all_of.hpp>
#include <sprout/algorithm/any_of.hpp>
#include <sprout/algorithm/none_of.hpp>
#include <sprout/algorithm/one_of.hpp>
#include <sprout/algorithm/find.hpp>
#include <sprout/algorithm/find_if.hpp>
#include <sprout/algorithm/find_if_not.hpp>
@ -36,5 +37,13 @@
#include <sprout/algorithm/max_element.hpp>
#include <sprout/algorithm/minmax_element.hpp>
#include <sprout/algorithm/lexicographical_compare.hpp>
#include <sprout/algorithm/all_of_equal.hpp>
#include <sprout/algorithm/any_of_equal.hpp>
#include <sprout/algorithm/none_of_equal.hpp>
#include <sprout/algorithm/one_of_equal.hpp>
#include <sprout/algorithm/is_increasing.hpp>
#include <sprout/algorithm/is_decreasing.hpp>
#include <sprout/algorithm/is_strictly_increasing.hpp>
#include <sprout/algorithm/is_strictly_decreasing.hpp>
#endif // #ifndef SPROUT_ALGORITHM_NON_MODIFYIING_HPP

View file

@ -0,0 +1,20 @@
#ifndef SPROUT_ALGORITHM_NONE_OF_EQUAL_HPP
#define SPROUT_ALGORITHM_NONE_OF_EQUAL_HPP
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
namespace sprout {
//
// none_of_equal
//
template<typename InputIterator, typename T>
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

View file

@ -0,0 +1,31 @@
#ifndef SPROUT_ALGORITHM_ONE_OF_HPP
#define SPROUT_ALGORITHM_ONE_OF_HPP
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/algorithm/find_if.hpp>
namespace sprout {
namespace detail {
template<typename InputIterator, typename Predicate>
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<typename InputIterator, typename Predicate>
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

View file

@ -0,0 +1,32 @@
#ifndef SPROUT_ALGORITHM_ONE_OF_EQUAL_HPP
#define SPROUT_ALGORITHM_ONE_OF_EQUAL_HPP
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/algorithm/none_of_equal.hpp>
#include <sprout/algorithm/find.hpp>
namespace sprout {
namespace detail {
template<typename InputIterator, typename T>
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<typename InputIterator, typename T>
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

View file

@ -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<std::size_t>(0), count_op());
return NS_SSCRISK_CEL_OR_SPROUT::accumulate(begin(), end(), static_cast<std::size_t>(0), count_op());
}
SPROUT_CONSTEXPR unsigned long
@ -1046,7 +1046,7 @@ namespace sprout {
}
template<typename Char, typename Traits, typename Alloc>
void
copy_to_string(std::basic_string<Char, Traits,Alloc>& s) const {
copy_to_string(std::basic_string<Char, Traits, Alloc>& s) const {
copy_to_string(s, Char('0'), Char('1'));
}

View file

@ -0,0 +1,21 @@
#ifndef SPROUT_RANGE_ALGORITHM_ALL_OF_EQUAL_HPP
#define SPROUT_RANGE_ALGORITHM_ALL_OF_EQUAL_HPP
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/all_of_equal.hpp>
namespace sprout {
namespace range {
//
// all_of_equal
//
template<typename Range, typename T>
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

View file

@ -0,0 +1,21 @@
#ifndef SPROUT_RANGE_ALGORITHM_ALL_OF_EQUAL_HPP
#define SPROUT_RANGE_ALGORITHM_ALL_OF_EQUAL_HPP
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/any_of_equal.hpp>
namespace sprout {
namespace range {
//
// any_of_equal
//
template<typename Range, typename T>
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

View file

@ -0,0 +1,21 @@
#ifndef SPROUT_RANGE_ALGORITHM_IS_DECREASING_HPP
#define SPROUT_RANGE_ALGORITHM_IS_DECREASING_HPP
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/is_decreasing.hpp>
namespace sprout {
namespace range {
//
// is_decreasing
//
template<typename Range>
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

View file

@ -0,0 +1,21 @@
#ifndef SPROUT_RANGE_ALGORITHM_IS_INCREASING_HPP
#define SPROUT_RANGE_ALGORITHM_IS_INCREASING_HPP
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/is_increasing.hpp>
namespace sprout {
namespace range {
//
// is_increasing
//
template<typename Range>
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

View file

@ -0,0 +1,21 @@
#ifndef SPROUT_RANGE_ALGORITHM_IS_STRICTLY_DECREASING_HPP
#define SPROUT_RANGE_ALGORITHM_IS_STRICTLY_DECREASING_HPP
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/is_strictly_decreasing.hpp>
namespace sprout {
namespace range {
//
// is_strictly_decreasing
//
template<typename Range>
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

View file

@ -0,0 +1,21 @@
#ifndef SPROUT_RANGE_ALGORITHM_IS_STRICTLY_INCREASING_HPP
#define SPROUT_RANGE_ALGORITHM_IS_STRICTLY_INCREASING_HPP
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/is_strictly_increasing.hpp>
namespace sprout {
namespace range {
//
// is_strictly_increasing
//
template<typename Range>
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

View file

@ -5,6 +5,7 @@
#include <sprout/range/algorithm/all_of.hpp>
#include <sprout/range/algorithm/any_of.hpp>
#include <sprout/range/algorithm/none_of.hpp>
#include <sprout/range/algorithm/one_of.hpp>
#include <sprout/range/algorithm/find.hpp>
#include <sprout/range/algorithm/find_if.hpp>
#include <sprout/range/algorithm/find_if_not.hpp>
@ -33,5 +34,13 @@
#include <sprout/range/algorithm/max_element.hpp>
#include <sprout/range/algorithm/minmax_element.hpp>
#include <sprout/range/algorithm/lexicographical_compare.hpp>
#include <sprout/range/algorithm/all_of_equal.hpp>
#include <sprout/range/algorithm/any_of_equal.hpp>
#include <sprout/range/algorithm/none_of_equal.hpp>
#include <sprout/range/algorithm/one_of_equal.hpp>
#include <sprout/range/algorithm/is_increasing.hpp>
#include <sprout/range/algorithm/is_decreasing.hpp>
#include <sprout/range/algorithm/is_strictly_increasing.hpp>
#include <sprout/range/algorithm/is_strictly_decreasing.hpp>
#endif // #ifndef SPROUT_RANGE_ALGORITHM_NON_MODIFYIING_HPP

View file

@ -0,0 +1,21 @@
#ifndef SPROUT_RANGE_ALGORITHM_NONE_OF_EQUAL_HPP
#define SPROUT_RANGE_ALGORITHM_NONE_OF_EQUAL_HPP
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/none_of_equal.hpp>
namespace sprout {
namespace range {
//
// none_of_equal
//
template<typename Range, typename T>
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

View file

@ -0,0 +1,21 @@
#ifndef SPROUT_RANGE_ALGORITHM_ONE_OF_HPP
#define SPROUT_RANGE_ALGORITHM_ONE_OF_HPP
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/one_of.hpp>
namespace sprout {
namespace range {
//
// one_of
//
template<typename Range, typename Predicate>
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

View file

@ -0,0 +1,21 @@
#ifndef SPROUT_RANGE_ALGORITHM_ONE_OF_EQUAL_HPP
#define SPROUT_RANGE_ALGORITHM_ONE_OF_EQUAL_HPP
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/one_of_equal.hpp>
namespace sprout {
namespace range {
//
// one_of_equal
//
template<typename Range, typename T>
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

View file

@ -20,7 +20,7 @@ namespace sprout {
}
template<typename Input, typename Result, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::algorithm<Result>::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