File indexing completed on 2025-11-04 09:41:40
0001 
0002 
0003 
0004 
0005 
0006 
0007 
0008 
0009 
0010 
0011 #ifndef BOOST_COMPUTE_ITERATOR_DISCARD_ITERATOR_HPP
0012 #define BOOST_COMPUTE_ITERATOR_DISCARD_ITERATOR_HPP
0013 
0014 #include <string>
0015 #include <cstddef>
0016 #include <iterator>
0017 
0018 #include <boost/config.hpp>
0019 #include <boost/iterator/iterator_facade.hpp>
0020 
0021 #include <boost/compute/detail/meta_kernel.hpp>
0022 #include <boost/compute/type_traits/is_device_iterator.hpp>
0023 
0024 namespace boost {
0025 namespace compute {
0026 
0027 
0028 class discard_iterator;
0029 
0030 namespace detail {
0031 
0032 
0033 
0034 struct discard_iterator_base
0035 {
0036     typedef ::boost::iterator_facade<
0037         ::boost::compute::discard_iterator,
0038         void,
0039         ::std::random_access_iterator_tag,
0040         void *
0041     > type;
0042 };
0043 
0044 template<class IndexExpr>
0045 struct discard_iterator_index_expr
0046 {
0047     typedef void result_type;
0048 
0049     discard_iterator_index_expr(const IndexExpr &expr)
0050         : m_expr(expr)
0051     {
0052     }
0053 
0054     IndexExpr m_expr;
0055 };
0056 
0057 template<class IndexExpr>
0058 inline meta_kernel& operator<<(meta_kernel &kernel,
0059                                const discard_iterator_index_expr<IndexExpr> &expr)
0060 {
0061     (void) expr;
0062 
0063     return kernel;
0064 }
0065 
0066 } 
0067 
0068 
0069 
0070 
0071 
0072 class discard_iterator : public detail::discard_iterator_base::type
0073 {
0074 public:
0075     typedef detail::discard_iterator_base::type super_type;
0076     typedef super_type::reference reference;
0077     typedef super_type::difference_type difference_type;
0078 
0079     discard_iterator(size_t index = 0)
0080         : m_index(index)
0081     {
0082     }
0083 
0084     discard_iterator(const discard_iterator &other)
0085         : m_index(other.m_index)
0086     {
0087     }
0088 
0089     discard_iterator& operator=(const discard_iterator &other)
0090     {
0091         if(this != &other){
0092             m_index = other.m_index;
0093         }
0094 
0095         return *this;
0096     }
0097 
0098     ~discard_iterator()
0099     {
0100     }
0101 
0102     
0103     template<class Expr>
0104     detail::discard_iterator_index_expr<Expr>
0105     operator[](const Expr &expr) const
0106     {
0107         return detail::discard_iterator_index_expr<Expr>(expr);
0108     }
0109 
0110 private:
0111     friend class ::boost::iterator_core_access;
0112 
0113     
0114     reference dereference() const
0115     {
0116         return 0;
0117     }
0118 
0119     
0120     bool equal(const discard_iterator &other) const
0121     {
0122         return m_index == other.m_index;
0123     }
0124 
0125     
0126     void increment()
0127     {
0128         m_index++;
0129     }
0130 
0131     
0132     void decrement()
0133     {
0134         m_index--;
0135     }
0136 
0137     
0138     void advance(difference_type n)
0139     {
0140         m_index = static_cast<size_t>(static_cast<difference_type>(m_index) + n);
0141     }
0142 
0143     
0144     difference_type distance_to(const discard_iterator &other) const
0145     {
0146         return static_cast<difference_type>(other.m_index - m_index);
0147     }
0148 
0149 private:
0150     size_t m_index;
0151 };
0152 
0153 
0154 
0155 
0156 
0157 
0158 inline discard_iterator make_discard_iterator(size_t index = 0)
0159 {
0160     return discard_iterator(index);
0161 }
0162 
0163 
0164 template<>
0165 struct is_device_iterator<discard_iterator> : boost::true_type {};
0166 
0167 } 
0168 } 
0169 
0170 #endif