Allow hidl_vec initializer to take arbitrary type.
In constructor, std::initializer_list<int> -> std::initializer_list<T>
Test: libhidl_test
Change-Id: I286ad9e2a31cf4dedb7f8b4051379ae5f3849fd0
diff --git a/include/hidl/HidlSupport.h b/include/hidl/HidlSupport.h
index d2a0a8a..4e63613 100644
--- a/include/hidl/HidlSupport.h
+++ b/include/hidl/HidlSupport.h
@@ -129,12 +129,12 @@
*this = std::move(other);
}
- hidl_vec(const std::initializer_list<int> list)
+ hidl_vec(const std::initializer_list<T> list)
: mSize(list.size()),
mOwnsBuffer(true) {
mBuffer = new T[mSize];
- int idx = 0;
+ size_t idx = 0;
for (auto it = list.begin(); it != list.end(); ++it) {
mBuffer[idx++] = *it;
}
diff --git a/test/main.cpp b/test/main.cpp
index a7dc243..d95488b 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -91,7 +91,7 @@
EXPECT_ARRAYEQ(v2, v, 3);
hidl_vec<int32_t> v3 = {5, 6, 7}; // initializer_list
- EXPECT_EQ(v3.size(), 3);
+ EXPECT_EQ(v3.size(), 3ul);
EXPECT_ARRAYEQ(v3, array, v3.size());
}