28 #ifndef REMORA_CPU_VECTOR_HPP 29 #define REMORA_CPU_VECTOR_HPP 33 #include "../detail/vector_proxy_classes.hpp" 34 #include <initializer_list> 36 #include <boost/serialization/vector.hpp> 37 #include <boost/serialization/nvp.hpp> 38 #include <boost/serialization/collection_size_type.hpp> 39 #include <boost/serialization/array.hpp> 43 class vector<T,cpu_tag>:
public vector_container<vector<T, cpu_tag>, cpu_tag > {
45 typedef vector<T> self_type;
46 typedef std::vector<typename std::conditional<std::is_same<T,bool>::value,char,T>::type > array_type;
48 typedef typename array_type::value_type value_type;
49 typedef typename array_type::const_reference const_reference;
50 typedef typename array_type::reference reference;
51 typedef typename array_type::size_type size_type;
53 typedef vector_reference<self_type const> const_closure_type;
54 typedef vector_reference<self_type> closure_type;
55 typedef dense_vector_storage<value_type, continuous_dense_tag> storage_type;
56 typedef dense_vector_storage<value_type const, continuous_dense_tag> const_storage_type;
57 typedef elementwise<dense_tag> evaluation_category;
68 explicit vector(size_type size):m_storage(size) {}
73 vector(size_type size,
const value_type& init):m_storage(size, init) {}
77 vector(vector
const& v) =
default;
82 vector(vector && v): m_storage(
std::move(v.m_storage)){}
84 vector(std::initializer_list<T> list) : m_storage(list.begin(),list.end()){}
88 vector(Iter begin, Iter end):m_storage(begin,end){}
93 vector(vector_expression<E, cpu_tag>
const& e):m_storage(e().size()) {
105 vector& operator = (vector
const& v) =
default;
111 vector& operator = (vector && v){
112 m_storage = std::move(v.m_storage);
121 vector& operator = (vector_container<C, cpu_tag>
const& v) {
123 return assign(*
this, v);
131 vector& operator = (vector_expression<E, cpu_tag>
const& e) {
132 self_type temporary(e);
133 swap(*
this,temporary);
142 size_type size()
const {
143 return m_storage.size();
147 storage_type raw_storage(){
148 return {m_storage.data(),1};
152 const_storage_type raw_storage()
const{
153 return {m_storage.data(),1};
155 typename device_traits<cpu_tag>::queue_type& queue(){
156 return device_traits<cpu_tag>::default_queue();
165 size_type max_size()
const {
166 return m_storage.max_size();
172 return m_storage.empty();
177 void resize(size_type size) {
178 m_storage.resize(size);
188 const_reference operator()(size_type i)
const {
189 REMORA_RANGE_CHECK(i < size());
196 reference operator()(size_type i) {
197 REMORA_RANGE_CHECK(i < size());
203 const_reference operator [](size_type i)
const {
204 REMORA_RANGE_CHECK(i < size());
210 reference operator [](size_type i) {
211 REMORA_RANGE_CHECK(i < size());
220 const_reference front()
const{
225 return m_storage[size()-1];
228 const_reference back()
const{
229 return m_storage[size()-1];
233 void push_back(value_type
const& element){
234 m_storage.push_back(element);
239 std::fill(m_storage.begin(), m_storage.end(), value_type());
243 typedef iterators::dense_storage_iterator<value_type> iterator;
244 typedef iterators::dense_storage_iterator<value_type const> const_iterator;
247 const_iterator cbegin()
const {
248 return const_iterator(m_storage.data(),0);
252 const_iterator cend()
const {
253 return const_iterator(m_storage.data()+size(),size());
257 const_iterator begin()
const {
262 const_iterator end()
const {
268 return iterator(m_storage.data(),0);
273 return iterator(m_storage.data()+size(),size());
277 iterator set_element(iterator pos, size_type index, value_type value) {
278 REMORA_SIZE_CHECK(pos.index() == index);
279 (*this)(index) = value;
284 iterator clear_element(iterator pos) {
285 REMORA_SIZE_CHECK(pos != end());
286 v(pos.index()) = value_type();
292 iterator clear_range(iterator start, iterator end) {
293 REMORA_RANGE_CHECK(start <= end);
294 std::fill(start,end,value_type());
298 void reserve(size_type) {}
303 friend void swap(vector& v1, vector& v2) {
304 v1.m_storage.swap(v2.m_storage);
313 template<
class Archive>
314 void serialize(Archive &ar,
const unsigned int file_version) {
315 boost::serialization::collection_size_type count(size());
317 if(!Archive::is_saving::value){
321 ar & boost::serialization::make_array(m_storage.data(),size());
326 array_type m_storage;