Skip to content

Commit

Permalink
Fix Thrust::vector ctor selection for int,int (NVIDIA#2261)
Browse files Browse the repository at this point in the history
thrust::device_vector<int> v(5, 10) should create a vector with 5 integers of value 10, and not attempt the iterator pair constructor.
  • Loading branch information
bernhardmgruber committed Aug 20, 2024
1 parent c92e8d4 commit 7bec0ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions thrust/thrust/detail/vector_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <thrust/iterator/iterator_traits.h>
#include <thrust/iterator/reverse_iterator.h>

#include <cuda/std/__iterator/iterator_traits.h>

#include <initializer_list>
#include <vector>

Expand Down Expand Up @@ -186,15 +188,17 @@ class vector_base
* \param first The beginning of the range.
* \param last The end of the range.
*/
template <typename InputIterator>
template <typename InputIterator,
::cuda::std::__enable_if_t<::cuda::std::__is_cpp17_input_iterator<InputIterator>::value, int> = 0>
vector_base(InputIterator first, InputIterator last);

/*! This constructor builds a vector_base from a range.
* \param first The beginning of the range.
* \param last The end of the range.
* \param alloc The allocator to use by this vector_base.
*/
template <typename InputIterator>
template <typename InputIterator,
::cuda::std::__enable_if_t<::cuda::std::__is_cpp17_input_iterator<InputIterator>::value, int> = 0>
vector_base(InputIterator first, InputIterator last, const Alloc& alloc);

/*! The destructor erases the elements.
Expand Down
6 changes: 4 additions & 2 deletions thrust/thrust/detail/vector_base.inl
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ void vector_base<T, Alloc>::range_init(ForwardIterator first, ForwardIterator la
} // end vector_base::range_init()

template <typename T, typename Alloc>
template <typename InputIterator>
template <typename InputIterator,
::cuda::std::__enable_if_t<::cuda::std::__is_cpp17_input_iterator<InputIterator>::value, int>>
vector_base<T, Alloc>::vector_base(InputIterator first, InputIterator last)
: m_storage()
, m_size(0)
Expand All @@ -283,7 +284,8 @@ vector_base<T, Alloc>::vector_base(InputIterator first, InputIterator last)
} // end vector_base::vector_base()

template <typename T, typename Alloc>
template <typename InputIterator>
template <typename InputIterator,
::cuda::std::__enable_if_t<::cuda::std::__is_cpp17_input_iterator<InputIterator>::value, int>>
vector_base<T, Alloc>::vector_base(InputIterator first, InputIterator last, const Alloc& alloc)
: m_storage(alloc)
, m_size(0)
Expand Down

0 comments on commit 7bec0ce

Please sign in to comment.