123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- #ifndef BOOST_COMPUTE_ITERATOR_DISCARD_ITERATOR_HPP
- #define BOOST_COMPUTE_ITERATOR_DISCARD_ITERATOR_HPP
- #include <string>
- #include <cstddef>
- #include <iterator>
- #include <boost/config.hpp>
- #include <boost/iterator/iterator_facade.hpp>
- #include <boost/compute/detail/meta_kernel.hpp>
- #include <boost/compute/type_traits/is_device_iterator.hpp>
- namespace boost {
- namespace compute {
- class discard_iterator;
- namespace detail {
- struct discard_iterator_base
- {
- typedef ::boost::iterator_facade<
- ::boost::compute::discard_iterator,
- void,
- ::std::random_access_iterator_tag,
- void *
- > type;
- };
- template<class IndexExpr>
- struct discard_iterator_index_expr
- {
- typedef void result_type;
- discard_iterator_index_expr(const IndexExpr &expr)
- : m_expr(expr)
- {
- }
- IndexExpr m_expr;
- };
- template<class IndexExpr>
- inline meta_kernel& operator<<(meta_kernel &kernel,
- const discard_iterator_index_expr<IndexExpr> &expr)
- {
- (void) expr;
- return kernel;
- }
- }
- class discard_iterator : public detail::discard_iterator_base::type
- {
- public:
- typedef detail::discard_iterator_base::type super_type;
- typedef super_type::reference reference;
- typedef super_type::difference_type difference_type;
- discard_iterator(size_t index = 0)
- : m_index(index)
- {
- }
- discard_iterator(const discard_iterator &other)
- : m_index(other.m_index)
- {
- }
- discard_iterator& operator=(const discard_iterator &other)
- {
- if(this != &other){
- m_index = other.m_index;
- }
- return *this;
- }
- ~discard_iterator()
- {
- }
-
- template<class Expr>
- detail::discard_iterator_index_expr<Expr>
- operator[](const Expr &expr) const
- {
- return detail::discard_iterator_index_expr<Expr>(expr);
- }
- private:
- friend class ::boost::iterator_core_access;
-
- reference dereference() const
- {
- return 0;
- }
-
- bool equal(const discard_iterator &other) const
- {
- return m_index == other.m_index;
- }
-
- void increment()
- {
- m_index++;
- }
-
- void decrement()
- {
- m_index--;
- }
-
- void advance(difference_type n)
- {
- m_index = static_cast<size_t>(static_cast<difference_type>(m_index) + n);
- }
-
- difference_type distance_to(const discard_iterator &other) const
- {
- return static_cast<difference_type>(other.m_index - m_index);
- }
- private:
- size_t m_index;
- };
- inline discard_iterator make_discard_iterator(size_t index = 0)
- {
- return discard_iterator(index);
- }
- template<>
- struct is_device_iterator<discard_iterator> : boost::true_type {};
- }
- }
- #endif
|