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

58 lines
1.9 KiB
C++
Raw Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
Copyright (c) 2011-2017 Bolero MURAKAMI
2013-08-08 09:54:33 +00:00
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_ITERATOR_UNIQUE_ITERATOR_HPP
#define SPROUT_ITERATOR_UNIQUE_ITERATOR_HPP
#include <sprout/config.hpp>
#include <sprout/iterator/adjacent_filter_iterator.hpp>
#include <sprout/functional/equal_to.hpp>
namespace sprout {
//
// unique_filter
//
template<typename Predicate = sprout::equal_to<> >
class unique_filter {
public:
typedef bool result_type;
private:
Predicate pred_;
public:
SPROUT_CONSTEXPR unique_filter()
: pred_()
{}
explicit SPROUT_CONSTEXPR unique_filter(Predicate pred)
: pred_(pred)
{}
template<typename T, typename U>
SPROUT_CONSTEXPR bool operator()(T const& lhs, U const& rhs) const {
return !pred_(lhs, rhs);
}
};
//
// make_unique_iterator
//
template<typename Predicate, typename Iterator>
inline SPROUT_CONSTEXPR sprout::adjacent_filter_iterator<sprout::unique_filter<Predicate>, Iterator>
make_unique_iterator(Predicate pred, Iterator it, Iterator last = Iterator()) {
return sprout::adjacent_filter_iterator<sprout::unique_filter<Predicate>, Iterator>(
sprout::unique_filter<Predicate>(pred), it, last
);
}
template<typename Iterator>
inline SPROUT_CONSTEXPR sprout::adjacent_filter_iterator<sprout::unique_filter<>, Iterator>
make_unique_iterator(Iterator it, Iterator last = Iterator()) {
return sprout::adjacent_filter_iterator<sprout::unique_filter<>, Iterator>(
sprout::unique_filter<>(), it, last
);
}
} // namespace sprout
#endif // SPROUT_ITERATOR_UNIQUE_ITERATOR_HPP