Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Enable construction of vectors from std::initializer_list #1836

Merged
merged 3 commits into from
Feb 21, 2023

Conversation

miscco
Copy link
Collaborator

@miscco miscco commented Dec 5, 2022

This fixes #1835 and enables construction of vectors from an initializer_list as well as assignment.

@miscco
Copy link
Collaborator Author

miscco commented Dec 5, 2022

run tests

@miscco
Copy link
Collaborator Author

miscco commented Dec 5, 2022

run tests

Copy link
Collaborator

@gevtushenko gevtushenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the addition! A few optional comments below.

thrust/device_vector.h Outdated Show resolved Hide resolved
thrust/host_vector.h Outdated Show resolved Hide resolved
thrust/device_vector.h Outdated Show resolved Hide resolved
testing/vector.cu Show resolved Hide resolved
@miscco
Copy link
Collaborator Author

miscco commented Dec 6, 2022

run tests

Comment on lines +198 to +205
template<typename T, typename Alloc>
vector_base<T,Alloc>
::vector_base(std::initializer_list<T> il)
:m_storage(),
m_size(0)
{
range_init(il.begin(), il.end());
} // end vector_base::vector_base()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm lazy, so I'm always a fan of delegating to other constructors when possible. In this case, we can delegate to the iterator pair ctor:

::vector_base(InputIterator first,

Suggested change
template<typename T, typename Alloc>
vector_base<T,Alloc>
::vector_base(std::initializer_list<T> il)
:m_storage(),
m_size(0)
{
range_init(il.begin(), il.end());
} // end vector_base::vector_base()
template<typename T, typename Alloc>
vector_base<T,Alloc>
::vector_base(std::initializer_list<T> il) : vector_base(std::cbegin(il), std::cend(il)) {}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did not touch those constructors and we should either move all of them to a consistent pattern or leave them as is.

@miscco miscco merged commit 29305f6 into NVIDIA:main Feb 21, 2023
@miscco miscco deleted the vector_initializer_list branch February 21, 2023 11:16
github-actions bot pushed a commit that referenced this pull request Feb 21, 2023
…alizer_list` (#1836)

* Enable construction of vectors from `std::initializer_list` 29305f6
@alliepiper alliepiper added this to the 2.1.0 milestone Mar 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

thrust::device_vector should have an std::initializer_list constructor
4 participants