-
Notifications
You must be signed in to change notification settings - Fork 758
Enable construction of vectors from std::initializer_list
#1836
Conversation
run tests |
run tests |
There was a problem hiding this 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.
run tests |
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() |
There was a problem hiding this comment.
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:
thrust/thrust/detail/vector_base.inl
Line 309 in 37a638e
::vector_base(InputIterator first, |
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)) {} |
There was a problem hiding this comment.
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.
This fixes #1835 and enables construction of vectors from an
initializer_list
as well as assignment.