2012-10-13 03:49:23 +00:00
|
|
|
#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
|
2012-12-16 15:36:19 +00:00
|
|
|
|
2012-10-13 03:49:23 +00:00
|
|
|
//
|
|
|
|
// one_of_equal
|
|
|
|
//
|
2012-12-16 15:36:19 +00:00
|
|
|
// recursion depth:
|
|
|
|
// [first, last) is RandomAccessIterator -> O(log N)
|
|
|
|
// otherwise -> O(N)
|
|
|
|
//
|
2012-10-13 03:49:23 +00:00
|
|
|
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
|