| 47 | /// \see \ref vector "vector<T>" |
| 48 | template<class T, std::size_t N> |
| 49 | class array |
| 50 | { |
| 51 | public: |
| 52 | typedef T value_type; |
| 53 | typedef std::size_t size_type; |
| 54 | typedef ptrdiff_t difference_type; |
| 55 | typedef detail::buffer_value<T> reference; |
| 56 | typedef const detail::buffer_value<T> const_reference; |
| 57 | typedef T* pointer; |
| 58 | typedef const T* const_pointer; |
| 59 | typedef buffer_iterator<T> iterator; |
| 60 | typedef buffer_iterator<T> const_iterator; |
| 61 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 62 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 63 | |
| 64 | enum { |
| 65 | static_size = N |
| 66 | }; |
| 67 | |
| 68 | explicit array(const context &context = system::default_context()) |
| 69 | : m_buffer(context, sizeof(T) * N) |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | array(const array<T, N> &other) |
| 74 | : m_buffer(other.m_buffer.get_context(), sizeof(T) * N) |
| 75 | { |
| 76 | command_queue queue = default_queue(); |
| 77 | boost::compute::copy(other.begin(), other.end(), begin(), queue); |
| 78 | queue.finish(); |
| 79 | } |
| 80 | |
| 81 | array(const boost::array<T, N> &array, |
| 82 | const context &context = system::default_context()) |
| 83 | : m_buffer(context, sizeof(T) * N) |
| 84 | { |
| 85 | command_queue queue = default_queue(); |
| 86 | boost::compute::copy(array.begin(), array.end(), begin(), queue); |
| 87 | queue.finish(); |
| 88 | } |
| 89 | |
| 90 | array(const array<T, N> &other, |
| 91 | const command_queue &queue) |
| 92 | : m_buffer(other.m_buffer.get_context(), sizeof(T) * N) |
| 93 | { |
| 94 | boost::compute::copy(other.begin(), other.end(), begin(), queue); |
| 95 | } |
| 96 | |
| 97 | array<T, N>& operator=(const array<T, N> &other) |
| 98 | { |
| 99 | if(this != &other){ |
| 100 | command_queue queue = default_queue(); |
| 101 | boost::compute::copy(other.begin(), other.end(), begin(), queue); |
| 102 | queue.finish(); |
| 103 | } |
| 104 | |
| 105 | return *this; |
| 106 | } |