Commit c072daec by Shahbaz Youssefi Committed by Angle LUCI CQ

Add FastVector constructor with begin/end iterators

Useful to construct a FastVector out of a subrange of another container. Bug: angleproject:4889 Change-Id: I0e62b601c7d171167343d526d198fa21ba52f0f9 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2920191Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
parent eeeeed39
...@@ -41,6 +41,9 @@ class FastVector final ...@@ -41,6 +41,9 @@ class FastVector final
FastVector(FastVector<T, N, Storage> &&other); FastVector(FastVector<T, N, Storage> &&other);
FastVector(std::initializer_list<value_type> init); FastVector(std::initializer_list<value_type> init);
template <class InputIt, std::enable_if_t<!std::is_integral<InputIt>::value, bool> = true>
FastVector(InputIt first, InputIt last);
FastVector<T, N, Storage> &operator=(const FastVector<T, N, Storage> &other); FastVector<T, N, Storage> &operator=(const FastVector<T, N, Storage> &other);
FastVector<T, N, Storage> &operator=(FastVector<T, N, Storage> &&other); FastVector<T, N, Storage> &operator=(FastVector<T, N, Storage> &&other);
FastVector<T, N, Storage> &operator=(std::initializer_list<value_type> init); FastVector<T, N, Storage> &operator=(std::initializer_list<value_type> init);
...@@ -139,11 +142,8 @@ FastVector<T, N, Storage>::FastVector(size_type count) ...@@ -139,11 +142,8 @@ FastVector<T, N, Storage>::FastVector(size_type count)
template <class T, size_t N, class Storage> template <class T, size_t N, class Storage>
FastVector<T, N, Storage>::FastVector(const FastVector<T, N, Storage> &other) FastVector<T, N, Storage>::FastVector(const FastVector<T, N, Storage> &other)
{ : FastVector(other.begin(), other.end())
ensure_capacity(other.mSize); {}
mSize = other.mSize;
std::copy(other.begin(), other.end(), begin());
}
template <class T, size_t N, class Storage> template <class T, size_t N, class Storage>
FastVector<T, N, Storage>::FastVector(FastVector<T, N, Storage> &&other) : FastVector() FastVector<T, N, Storage>::FastVector(FastVector<T, N, Storage> &&other) : FastVector()
...@@ -158,6 +158,15 @@ FastVector<T, N, Storage>::FastVector(std::initializer_list<value_type> init) ...@@ -158,6 +158,15 @@ FastVector<T, N, Storage>::FastVector(std::initializer_list<value_type> init)
} }
template <class T, size_t N, class Storage> template <class T, size_t N, class Storage>
template <class InputIt, std::enable_if_t<!std::is_integral<InputIt>::value, bool>>
FastVector<T, N, Storage>::FastVector(InputIt first, InputIt last)
{
mSize = last - first;
ensure_capacity(mSize);
std::copy(first, last, begin());
}
template <class T, size_t N, class Storage>
FastVector<T, N, Storage> &FastVector<T, N, Storage>::operator=( FastVector<T, N, Storage> &FastVector<T, N, Storage>::operator=(
const FastVector<T, N, Storage> &other) const FastVector<T, N, Storage> &other)
{ {
......
...@@ -32,6 +32,12 @@ TEST(FastVector, Constructors) ...@@ -32,6 +32,12 @@ TEST(FastVector, Constructors)
FastVector<int, 5> copyRValue(std::move(count)); FastVector<int, 5> copyRValue(std::move(count));
EXPECT_EQ(3u, copyRValue.size()); EXPECT_EQ(3u, copyRValue.size());
FastVector<int, 5> copyIter(countAndValue.begin(), countAndValue.end());
EXPECT_EQ(copyIter, countAndValue);
FastVector<int, 5> copyIterEmpty(countAndValue.begin(), countAndValue.begin());
EXPECT_TRUE(copyIterEmpty.empty());
FastVector<int, 5> initializerList{1, 2, 3, 4, 5}; FastVector<int, 5> initializerList{1, 2, 3, 4, 5};
EXPECT_EQ(5u, initializerList.size()); EXPECT_EQ(5u, initializerList.size());
EXPECT_EQ(3, initializerList[2]); EXPECT_EQ(3, initializerList[2]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment