BLI: add Vector/Array.fill methods
This commit is contained in:
parent
8cbbdedaf4
commit
579b180053
|
@ -268,6 +268,14 @@ class Array {
|
|||
return size_ == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the given value to every element in the array.
|
||||
*/
|
||||
void fill(const T &value) const
|
||||
{
|
||||
initialized_fill_n(data_, size_, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pointer to the beginning of the array.
|
||||
*/
|
||||
|
|
|
@ -702,6 +702,14 @@ class Vector {
|
|||
return this->first_index_of_try(value) != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the given value to every element in the vector.
|
||||
*/
|
||||
void fill(const T &value) const
|
||||
{
|
||||
initialized_fill_n(begin_, this->size(), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get access to the underlying array.
|
||||
*/
|
||||
|
|
|
@ -161,4 +161,16 @@ TEST(array, NoInitializationSizeConstructor)
|
|||
}
|
||||
}
|
||||
|
||||
TEST(array, Fill)
|
||||
{
|
||||
Array<int> array(5);
|
||||
array.fill(3);
|
||||
EXPECT_EQ(array.size(), 5u);
|
||||
EXPECT_EQ(array[0], 3);
|
||||
EXPECT_EQ(array[1], 3);
|
||||
EXPECT_EQ(array[2], 3);
|
||||
EXPECT_EQ(array[3], 3);
|
||||
EXPECT_EQ(array[4], 3);
|
||||
}
|
||||
|
||||
} // namespace blender
|
||||
|
|
|
@ -624,4 +624,16 @@ TEST(vector, ConstructVoidPointerVector)
|
|||
EXPECT_EQ(vec.size(), 3);
|
||||
}
|
||||
|
||||
TEST(vector, Fill)
|
||||
{
|
||||
Vector<int> vec(5);
|
||||
vec.fill(3);
|
||||
EXPECT_EQ(vec.size(), 5u);
|
||||
EXPECT_EQ(vec[0], 3);
|
||||
EXPECT_EQ(vec[1], 3);
|
||||
EXPECT_EQ(vec[2], 3);
|
||||
EXPECT_EQ(vec[3], 3);
|
||||
EXPECT_EQ(vec[4], 3);
|
||||
}
|
||||
|
||||
} // namespace blender
|
||||
|
|
Loading…
Reference in New Issue