thrust/device_vector.h

File members: thrust/device_vector.h

/*
 *  Copyright 2008-2018 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>

#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
#  pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
#  pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
#  pragma system_header
#endif // no system header
#include <thrust/detail/vector_base.h>
#include <thrust/device_allocator.h>

#include <initializer_list>
#include <utility>
#include <vector>

THRUST_NAMESPACE_BEGIN

template <typename T, typename Alloc = thrust::device_allocator<T>>
class device_vector : public detail::vector_base<T, Alloc>
{
private:
  using Parent = detail::vector_base<T, Alloc>;

public:
  using size_type  = typename Parent::size_type;
  using value_type = typename Parent::value_type;
  device_vector()
      : Parent()
  {}

  device_vector(const Alloc& alloc)
      : Parent(alloc)
  {}

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

  explicit device_vector(size_type n)
      : Parent(n)
  {}

  explicit device_vector(size_type n, const Alloc& alloc)
      : Parent(n, alloc)
  {}

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

  explicit device_vector(size_type n, const value_type& value, const Alloc& alloc)
      : Parent(n, value, alloc)
  {}

  device_vector(const device_vector& v)
      : Parent(v)
  {}

  device_vector(const device_vector& v, const Alloc& alloc)
      : Parent(v, alloc)
  {}

  device_vector(device_vector&& v)
      : Parent(std::move(v))
  {}

  device_vector(device_vector&& v, const Alloc& alloc)
      : Parent(std::move(v), alloc)
  {}

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

  device_vector& operator=(device_vector&& v)
  {
    Parent::operator=(std::move(v));
    return *this;
  }

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

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

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

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

  template <typename OtherT, typename OtherAlloc>
  device_vector(const detail::vector_base<OtherT, OtherAlloc>& v)
      : Parent(v)
  {}

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

  device_vector(std::initializer_list<T> il)
      : Parent(il)
  {}

  device_vector(std::initializer_list<T> il, const Alloc& alloc)
      : Parent(il, alloc)
  {}

  device_vector& operator=(std::initializer_list<T> il)
  {
    Parent::operator=(il);
    return *this;
  }

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

  template <typename InputIterator>
  device_vector(InputIterator first, InputIterator last, const Alloc& alloc)
      : Parent(first, last, alloc)
  {}

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

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

    size_type size() const;

    size_type max_size() const;

    void reserve(size_type n);

    size_type capacity() const;

    void shrink_to_fit();

    reference operator[](size_type n);

    const_reference operator[](size_type n) const;

    iterator begin();

    const_iterator begin() const;

    const_iterator cbegin() const;

    reverse_iterator rbegin();

    const_reverse_iterator rbegin() const;

    const_reverse_iterator crbegin() const;

    iterator end();

    const_iterator end() const;

    const_iterator cend() const;

    reverse_iterator rend();

    const_reverse_iterator rend() const;

    const_reverse_iterator crend() const;

    const_reference front() const;

    reference front();

    const_reference back() const;

    reference back();

    pointer data();

    const_pointer data() const;

    void clear();

    bool empty() const;

    void push_back(const value_type &x);

    void pop_back();

    void swap(device_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() const;
#endif // end doxygen-only members
};

template <typename T, typename Alloc>
void swap(device_vector<T, Alloc>& a, device_vector<T, Alloc>& b)
{
  a.swap(b);
}

THRUST_NAMESPACE_END