1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_UTILITY_EXTENTS_HPP
12 #define BOOST_COMPUTE_UTILITY_EXTENTS_HPP
17 #include <boost/compute/config.hpp>
19 #ifndef BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
20 #include <initializer_list>
23 #include <boost/array.hpp>
28 /// The extents class contains an array of n-dimensional extents.
35 typedef size_t size_type;
36 static const size_type static_size = N;
37 typedef boost::array<size_t, N> array_type;
38 typedef typename array_type::iterator iterator;
39 typedef typename array_type::const_iterator const_iterator;
41 /// Creates an extents object with each component set to zero.
45 /// extents<3> exts(); // (0, 0, 0)
52 /// Creates an extents object with each component set to \p value.
56 /// extents<3> exts(1); // (1, 1, 1)
58 explicit extents(size_t value)
60 m_extents.fill(value);
63 #ifndef BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
64 /// Creates an extents object with \p values.
65 extents(std::initializer_list<size_t> values)
67 BOOST_ASSERT(values.size() == N);
69 std::copy(values.begin(), values.end(), m_extents.begin());
71 #endif // BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
73 /// Returns the size (i.e. dimensionality) of the extents array.
74 size_type size() const
79 /// Returns the linear size of the extents. This is equivalent to the
80 /// product of each extent in each dimension.
81 size_type linear() const
83 return std::accumulate(
84 m_extents.begin(), m_extents.end(), 1, std::multiplies<size_type>()
88 /// Returns a pointer to the extents data array.
90 /// This is useful for passing the extents data to OpenCL APIs which
91 /// expect an array of \c size_t.
94 return m_extents.data();
98 const size_t* data() const
100 return m_extents.data();
105 return m_extents.begin();
108 const_iterator begin() const
110 return m_extents.begin();
113 const_iterator cbegin() const
115 return m_extents.cbegin();
120 return m_extents.end();
123 const_iterator end() const
125 return m_extents.end();
128 const_iterator cend() const
130 return m_extents.cend();
133 /// Returns a reference to the extent at \p index.
134 size_t& operator[](size_t index)
136 return m_extents[index];
140 const size_t& operator[](size_t index) const
142 return m_extents[index];
145 /// Returns \c true if the extents in \c *this are the same as \p other.
146 bool operator==(const extents &other) const
148 return m_extents == other.m_extents;
151 /// Returns \c true if the extents in \c *this are not the same as \p other.
152 bool operator!=(const extents &other) const
154 return m_extents != other.m_extents;
158 array_type m_extents;
161 } // end compute namespace
162 } // end boost namespace
164 #endif // BOOST_COMPUTE_UTILITY_EXTENTS_HPP