Program Listing for File host_vector.h

Return to documentation for file (thrust/host_vector.h)

/*
 *  Copyright 2008-2013 NVIDIA Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */


#pragma once

#include <thrust/detail/config.h>
#include <memory>
#include <thrust/detail/vector_base.h>
#include <vector>
#include <utility>

namespace thrust
{

// forward declaration of device_vector
template<typename T, typename Alloc> class device_vector;

template<typename T, typename Alloc = std::allocator<T> >
  class host_vector
    : public detail::vector_base<T,Alloc>
{
  private:
    typedef detail::vector_base<T,Alloc> Parent;

  public:
    typedef typename Parent::size_type  size_type;
    typedef typename Parent::value_type value_type;
    __host__
    host_vector(void)
      :Parent() {}

    //  Define an empty destructor to explicitly specify
    //  its execution space qualifier, as a workaround for nvcc warning
    __host__
    ~host_vector(void) {}

    __host__
    explicit host_vector(size_type n)
      :Parent(n) {}

    __host__
    explicit host_vector(size_type n, const value_type &value)
      :Parent(n,value) {}

    __host__
    host_vector(const host_vector &v)
      :Parent(v) {}

  #if __cplusplus >= 201103L

     __host__
    host_vector(host_vector &&v)
      :Parent(std::move(v)) {}
  #endif

  __host__
  host_vector &operator=(const host_vector &v)
  { Parent::operator=(v); return *this; }

  #if __cplusplus >= 201103L

     __host__
     host_vector &operator=(host_vector &&v)
     { Parent::operator=(std::move(v)); return *this; }
  #endif

    template<typename OtherT, typename OtherAlloc>
    __host__
    host_vector(const host_vector<OtherT,OtherAlloc> &v)
      :Parent(v) {}

    template<typename OtherT, typename OtherAlloc>
    __host__
    host_vector &operator=(const host_vector<OtherT,OtherAlloc> &v)
    { Parent::operator=(v); return *this; }

    template<typename OtherT, typename OtherAlloc>
    __host__
    host_vector(const std::vector<OtherT,OtherAlloc> &v)
      :Parent(v) {}

    template<typename OtherT, typename OtherAlloc>
    __host__
    host_vector &operator=(const std::vector<OtherT,OtherAlloc> &v)
    { Parent::operator=(v); return *this;}

    template<typename OtherT, typename OtherAlloc>
    __host__
    host_vector(const device_vector<OtherT,OtherAlloc> &v);

    template<typename OtherT, typename OtherAlloc>
    __host__
    host_vector &operator=(const device_vector<OtherT,OtherAlloc> &v)
    { Parent::operator=(v); return *this; }

    template<typename InputIterator>
    __host__
    host_vector(InputIterator first, InputIterator last)
      :Parent(first, last) {}

// declare these members for the purpose of Doxygenating them
// they actually exist in a derived-from class
#if 0

    void resize(size_type new_size, const value_type &x = value_type());

    size_type size(void) const;

    size_type max_size(void) const;

    void reserve(size_type n);

    size_type capacity(void) const;

    void shrink_to_fit(void);

    reference operator[](size_type n);

    const_reference operator[](size_type n) const;

    iterator begin(void);

    const_iterator begin(void) const;

    const_iterator cbegin(void) const;

    reverse_iterator rbegin(void);

    const_reverse_iterator rbegin(void) const;

    const_reverse_iterator crbegin(void) const;

    iterator end(void);

    const_iterator end(void) const;

    const_iterator cend(void) const;

    reverse_iterator rend(void);

    const_reverse_iterator rend(void) const;

    const_reverse_iterator crend(void) const;

    const_reference front(void) const;

    reference front(void);

    const_reference back(void) const;

    reference back(void);

    pointer data(void);

    const_pointer data(void) const;

    void clear(void);

    bool empty(void) const;

    void push_back(const value_type &x);

    void pop_back(void);

    void swap(host_vector &v);

    iterator erase(iterator pos);

    iterator erase(iterator first, iterator last);

    iterator insert(iterator position, const T &x);

    void insert(iterator position, size_type n, const T &x);

    template<typename InputIterator>
    void insert(iterator position, InputIterator first, InputIterator last);

    void assign(size_type n, const T &x);

    template<typename InputIterator>
    void assign(InputIterator first, InputIterator last);

    allocator_type get_allocator(void) const;
#endif // end doxygen-only members
}; // end host_vector

} // end thrust

#include <thrust/detail/host_vector.inl>