123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- #ifndef BOOST_COMPUTE_UTILITY_EXTENTS_HPP
- #define BOOST_COMPUTE_UTILITY_EXTENTS_HPP
- #include <functional>
- #include <numeric>
- #include <boost/compute/config.hpp>
- #ifndef BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
- #include <initializer_list>
- #endif
- #include <boost/array.hpp>
- namespace boost {
- namespace compute {
- template<size_t N>
- class extents
- {
- public:
- typedef size_t size_type;
- static const size_type static_size = N;
- typedef boost::array<size_t, N> array_type;
- typedef typename array_type::iterator iterator;
- typedef typename array_type::const_iterator const_iterator;
-
-
-
-
-
-
- extents()
- {
- m_extents.fill(0);
- }
-
-
-
-
-
-
- explicit extents(size_t value)
- {
- m_extents.fill(value);
- }
- #ifndef BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
-
- extents(std::initializer_list<size_t> values)
- {
- BOOST_ASSERT(values.size() == N);
- std::copy(values.begin(), values.end(), m_extents.begin());
- }
- #endif
-
- size_type size() const
- {
- return N;
- }
-
-
- size_type linear() const
- {
- return std::accumulate(
- m_extents.begin(), m_extents.end(), 1, std::multiplies<size_type>()
- );
- }
-
-
-
-
- size_t* data()
- {
- return m_extents.data();
- }
-
- const size_t* data() const
- {
- return m_extents.data();
- }
- iterator begin()
- {
- return m_extents.begin();
- }
- const_iterator begin() const
- {
- return m_extents.begin();
- }
- const_iterator cbegin() const
- {
- return m_extents.cbegin();
- }
- iterator end()
- {
- return m_extents.end();
- }
- const_iterator end() const
- {
- return m_extents.end();
- }
- const_iterator cend() const
- {
- return m_extents.cend();
- }
-
- size_t& operator[](size_t index)
- {
- return m_extents[index];
- }
-
- const size_t& operator[](size_t index) const
- {
- return m_extents[index];
- }
-
- bool operator==(const extents &other) const
- {
- return m_extents == other.m_extents;
- }
-
- bool operator!=(const extents &other) const
- {
- return m_extents != other.m_extents;
- }
- private:
- array_type m_extents;
- };
- }
- }
- #endif
|