Add initializer list to hidl_vec.
Test: libhidl_test
Change-Id: I7f25fee84feed31c3f84ca640156c0befea1d2c7
diff --git a/include/hidl/HidlSupport.h b/include/hidl/HidlSupport.h
index 1c468ed..d2a0a8a 100644
--- a/include/hidl/HidlSupport.h
+++ b/include/hidl/HidlSupport.h
@@ -125,10 +125,21 @@
}
hidl_vec(hidl_vec<T> &&other)
- : mOwnsBuffer(false) {
+ : mOwnsBuffer(false) {
*this = std::move(other);
}
+ hidl_vec(const std::initializer_list<int> list)
+ : mSize(list.size()),
+ mOwnsBuffer(true) {
+ mBuffer = new T[mSize];
+
+ int idx = 0;
+ for (auto it = list.begin(); it != list.end(); ++it) {
+ mBuffer[idx++] = *it;
+ }
+ }
+
hidl_vec(const std::vector<T> &other) : hidl_vec() {
*this = other;
}