| 102 | /// \see \ref array "array<T, N>", buffer |
| 103 | template<class T, class Alloc = buffer_allocator<T> > |
| 104 | class vector |
| 105 | { |
| 106 | public: |
| 107 | typedef T value_type; |
| 108 | typedef Alloc allocator_type; |
| 109 | typedef typename allocator_type::size_type size_type; |
| 110 | typedef typename allocator_type::difference_type difference_type; |
| 111 | typedef detail::buffer_value<T> reference; |
| 112 | typedef const detail::buffer_value<T> const_reference; |
| 113 | typedef typename allocator_type::pointer pointer; |
| 114 | typedef typename allocator_type::const_pointer const_pointer; |
| 115 | typedef buffer_iterator<T> iterator; |
| 116 | typedef buffer_iterator<T> const_iterator; |
| 117 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 118 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 119 | |
| 120 | /// Creates an empty vector in \p context. |
| 121 | explicit vector(const context &context = system::default_context()) |
| 122 | : m_size(0), |
| 123 | m_allocator(context) |
| 124 | { |
| 125 | m_data = m_allocator.allocate(_minimum_capacity()); |
| 126 | } |
| 127 | |
| 128 | /// Creates a vector with space for \p count elements in \p context. |
| 129 | /// |
| 130 | /// Note that unlike \c std::vector's constructor, this will not initialize |
| 131 | /// the values in the container. Either call the vector constructor which |
| 132 | /// takes a value to initialize with or use the fill() algorithm to set |
| 133 | /// the initial values. |
| 134 | /// |
| 135 | /// For example: |
| 136 | /// \code |
| 137 | /// // create a vector on the device with space for ten ints |
| 138 | /// boost::compute::vector<int> vec(10, context); |
| 139 | /// \endcode |
| 140 | explicit vector(size_type count, |
| 141 | const context &context = system::default_context()) |
| 142 | : m_size(count), |
| 143 | m_allocator(context) |
| 144 | { |
| 145 | m_data = m_allocator.allocate((std::max)(count, _minimum_capacity())); |
| 146 | } |
| 147 | |
| 148 | /// Creates a vector with space for \p count elements and sets each equal |
| 149 | /// to \p value. |
| 150 | /// |
| 151 | /// For example: |
| 152 | /// \code |
| 153 | /// // creates a vector with four values set to nine (e.g. [9, 9, 9, 9]). |
| 154 | /// boost::compute::vector<int> vec(4, 9, queue); |
| 155 | /// \endcode |
| 156 | vector(size_type count, |
| 157 | const T &value, |
| 158 | command_queue &queue = system::default_queue()) |
| 159 | : m_size(count), |
| 160 | m_allocator(queue.get_context()) |
| 161 | { |