ArrayView, adding ctor for fixed-size views of std::array.
This CL allows to reduce the code required to create fixed-size ArrayView objects for std::array instances. Instead of passing .data() and .size(), it is now sufficient to pass the std::array instance. When instancing an array view with variable size, a different ctor is called. Bug: webrtc:9076 Change-Id: I4fe133b27cd12827ed0206d40184279fc3a196f5 Reviewed-on: https://webrtc-review.googlesource.com/76160 Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23220}
This commit is contained in:
committed by
Commit Bot
parent
6e0c145538
commit
858c4d70cd
@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@ -180,6 +181,19 @@ TEST(ArrayViewTest, TestCopyAssignmentFixed) {
|
||||
// v = z; // Compile error, because can't drop const.
|
||||
}
|
||||
|
||||
TEST(ArrayViewTest, TestStdArray) {
|
||||
constexpr size_t size = 5;
|
||||
std::array<float, size> arr{};
|
||||
// Fixed size view.
|
||||
rtc::ArrayView<float, size> arr_view_fixed(arr);
|
||||
EXPECT_EQ(arr.data(), arr_view_fixed.data());
|
||||
static_assert(size == arr_view_fixed.size(), "");
|
||||
// Variable size view.
|
||||
rtc::ArrayView<float> arr_view(arr);
|
||||
EXPECT_EQ(arr.data(), arr_view.data());
|
||||
EXPECT_EQ(size, arr_view.size());
|
||||
}
|
||||
|
||||
TEST(ArrayViewTest, TestStdVector) {
|
||||
std::vector<int> v;
|
||||
v.push_back(3);
|
||||
|
||||
Reference in New Issue
Block a user