Thrust
host_vector.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2018 NVIDIA Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
23 #pragma once
24 
25 #include <thrust/detail/config.h>
26 #include <thrust/detail/memory_wrapper.h>
27 #include <thrust/detail/vector_base.h>
28 #include <vector>
29 #include <utility>
30 
31 THRUST_NAMESPACE_BEGIN
32 
50 template<typename T, typename Alloc = std::allocator<T> >
52  : public detail::vector_base<T,Alloc>
53 {
54  private:
55  typedef detail::vector_base<T,Alloc> Parent;
56 
57  public:
60  typedef typename Parent::size_type size_type;
61  typedef typename Parent::value_type value_type;
67  __host__
69  :Parent() {}
70 
74  __host__
75  host_vector(const Alloc &alloc)
76  :Parent(alloc) {}
77 
80  // Define an empty destructor to explicitly specify
81  // its execution space qualifier, as a workaround for nvcc warning
82  __host__
83  ~host_vector(void) {}
84 
89  __host__
90  explicit host_vector(size_type n)
91  :Parent(n) {}
92 
98  __host__
99  explicit host_vector(size_type n, const Alloc &alloc)
100  :Parent(n,alloc) {}
101 
107  __host__
108  explicit host_vector(size_type n, const value_type &value)
109  :Parent(n,value) {}
110 
117  __host__
118  explicit host_vector(size_type n, const value_type &value, const Alloc &alloc)
119  :Parent(n,value,alloc) {}
120 
124  __host__
126  :Parent(v) {}
127 
132  __host__
133  host_vector(const host_vector &v, const Alloc &alloc)
134  :Parent(v,alloc) {}
135 
136  #if THRUST_CPP_DIALECT >= 2011
137 
140  __host__
142  :Parent(std::move(v)) {}
143 
148  __host__
149  host_vector(host_vector &&v, const Alloc &alloc)
150  :Parent(std::move(v),alloc) {}
151  #endif
152 
156  __host__
158  { Parent::operator=(v); return *this; }
159 
160  #if THRUST_CPP_DIALECT >= 2011
161 
164  __host__
166  { Parent::operator=(std::move(v)); return *this; }
167  #endif
168 
172  template<typename OtherT, typename OtherAlloc>
173  __host__
175  :Parent(v) {}
176 
180  template<typename OtherT, typename OtherAlloc>
181  __host__
183  { Parent::operator=(v); return *this; }
184 
188  template<typename OtherT, typename OtherAlloc>
189  __host__
190  host_vector(const std::vector<OtherT,OtherAlloc> &v)
191  :Parent(v) {}
192 
196  template<typename OtherT, typename OtherAlloc>
197  __host__
198  host_vector &operator=(const std::vector<OtherT,OtherAlloc> &v)
199  { Parent::operator=(v); return *this;}
200 
206  template<typename OtherT, typename OtherAlloc>
207  __host__
208  host_vector(const detail::vector_base<OtherT,OtherAlloc> &v)
209  :Parent(v) {}
210 
215  template<typename OtherT, typename OtherAlloc>
216  __host__
217  host_vector &operator=(const detail::vector_base<OtherT,OtherAlloc> &v)
218  { Parent::operator=(v); return *this; }
219 
224  template<typename InputIterator>
225  __host__
226  host_vector(InputIterator first, InputIterator last)
227  :Parent(first, last) {}
228 
234  template<typename InputIterator>
235  __host__
236  host_vector(InputIterator first, InputIterator last, const Alloc &alloc)
237  :Parent(first, last, alloc) {}
238 
239 // declare these members for the purpose of Doxygenating them
240 // they actually exist in a derived-from class
241 #if 0
242 
252  void resize(size_type new_size, const value_type &x = value_type());
253 
256  size_type size(void) const;
257 
261  size_type max_size(void) const;
262 
269  void reserve(size_type n);
270 
274  size_type capacity(void) const;
275 
279  void shrink_to_fit(void);
280 
289  reference operator[](size_type n);
290 
299  const_reference operator[](size_type n) const;
300 
305  iterator begin(void);
306 
311  const_iterator begin(void) const;
312 
317  const_iterator cbegin(void) const;
318 
324  reverse_iterator rbegin(void);
325 
331  const_reverse_iterator rbegin(void) const;
332 
338  const_reverse_iterator crbegin(void) const;
339 
344  iterator end(void);
345 
350  const_iterator end(void) const;
351 
356  const_iterator cend(void) const;
357 
362  reverse_iterator rend(void);
363 
368  const_reverse_iterator rend(void) const;
369 
374  const_reverse_iterator crend(void) const;
375 
380  const_reference front(void) const;
381 
386  reference front(void);
387 
392  const_reference back(void) const;
393 
398  reference back(void);
399 
403  pointer data(void);
404 
408  const_pointer data(void) const;
409 
412  void clear(void);
413 
417  bool empty(void) const;
418 
422  void push_back(const value_type &x);
423 
427  void pop_back(void);
428 
432  void swap(host_vector &v);
433 
439  iterator erase(iterator pos);
440 
447  iterator erase(iterator first, iterator last);
448 
455  iterator insert(iterator position, const T &x);
456 
463  void insert(iterator position, size_type n, const T &x);
464 
474  template<typename InputIterator>
475  void insert(iterator position, InputIterator first, InputIterator last);
476 
482  void assign(size_type n, const T &x);
483 
490  template<typename InputIterator>
491  void assign(InputIterator first, InputIterator last);
492 
496  allocator_type get_allocator(void) const;
497 #endif // end doxygen-only members
498 };
499 
504 template<typename T, typename Alloc>
506 {
507  a.swap(b);
508 }
509 
513 THRUST_NAMESPACE_END
thrust::pointer< T, thrust::system::cpp::tag, thrust::tagged_reference< T, thrust::system::cpp::tag > > pointer
Definition: pointer.h:60
void swap(host_vector< T, Alloc > &a, host_vector< T, Alloc > &b)
Definition: host_vector.h:505
__host__ host_vector(size_type n, const Alloc &alloc)
Definition: host_vector.h:99
__host__ host_vector(host_vector &&v)
Definition: host_vector.h:141
__host__ host_vector(const host_vector< OtherT, OtherAlloc > &v)
Definition: host_vector.h:174
thrust::reference< T, thrust::system::cpp::tag > reference
Definition: pointer.h:98
__host__ host_vector(const host_vector &v)
Definition: host_vector.h:125
__host__ host_vector(size_type n, const value_type &value, const Alloc &alloc)
Definition: host_vector.h:118
Definition: optional.h:2876
__host__ host_vector(const std::vector< OtherT, OtherAlloc > &v)
Definition: host_vector.h:190
Definition: reverse_iterator.h:144
__host__ host_vector(const detail::vector_base< OtherT, OtherAlloc > &v)
Definition: host_vector.h:208
__host__ host_vector & operator=(const detail::vector_base< OtherT, OtherAlloc > &v)
Definition: host_vector.h:217
__host__ host_vector(host_vector &&v, const Alloc &alloc)
Definition: host_vector.h:149
__host__ host_vector(const Alloc &alloc)
Definition: host_vector.h:75
__host__ host_vector & operator=(const std::vector< OtherT, OtherAlloc > &v)
Definition: host_vector.h:198
__host__ host_vector(InputIterator first, InputIterator last)
Definition: host_vector.h:226
Definition: host_vector.h:51
__host__ host_vector & operator=(const host_vector &v)
Definition: host_vector.h:157
__host__ ~host_vector(void)
Definition: host_vector.h:83
__host__ host_vector & operator=(host_vector &&v)
Definition: host_vector.h:165
__host__ host_vector(InputIterator first, InputIterator last, const Alloc &alloc)
Definition: host_vector.h:236
__host__ host_vector & operator=(const host_vector< OtherT, OtherAlloc > &v)
Definition: host_vector.h:182
__host__ host_vector(size_type n)
Definition: host_vector.h:90
__host__ host_vector(size_type n, const value_type &value)
Definition: host_vector.h:108
__host__ host_vector(const host_vector &v, const Alloc &alloc)
Definition: host_vector.h:133
__host__ host_vector(void)
Definition: host_vector.h:68