i am working on a native executable using parcel. the executable is in c++ and will send the parcel to a java function, the parcel in java will use parcel.writetypedlist however writetypedlist is not available in c++ parcel so im stuck. i found this link https://android.googlesource.com/platform/system/tools/aidl/+/brillo-m10-dev/docs/aidl-cpp.md, in with it states "Consider an AIDL type in @nullable List<String> bar. This type indicates that the remote caller may pass in a list of strings, and that both the list and any string in the list may be null. This type will map to a C++ type unique_ptr<vector<unique_ptr<String16>>>* bar". however im looking for examples on how to initialize a vector of type unique_ptr<vector<unique_ptr<String16>>>* with 6 values in it 4 of which are null. any help or especialy any example would be greatly appreciated
type 'std::__1::unique_ptr<std::__1::vector<std::__1::unique_ptr<android::String16, std::__1::default_delete<android::String16> >, std::__1::allocator<std::__1::unique_ptr<android::String16, std::__1::default_delete<android::String16> > > >, std::__1::default_delete<std::__1::vector<std::__1::unique_ptr<android::String16, std::__1::default_delete<android::String16> >, std::__1::allocator<std::__1::unique_ptr<android::String16, std::__1::default_delete<android::String16> > > > > >' does not provide a subscript operator
vector[0] = std::move(String16("310"));
i should point out im new to c++
NOTE: the vector is being sent to a function requiring const std::unique_ptr<std::vector<std::unique_ptr<String16>>>& val, however the page i link to says i need to use unique_ptr<vector<unique_ptr<String16>>>* bar
qoute from page linked to "Note that by default, the generated C++ passes a const reference to the value of a parameter and rejects null references with a NullPointerException sent back the caller. Parameters marked with @nullable are passed by pointer, allowing native services to explicitly control whether they allow method overloading via null parameters. Java stubs and proxies currently do nothing with the @nullable annotation."
still not working
error: type 'std::__1::unique_ptr<std::__1::vector<std::__1::unique_ptr<android::String16, std::__1::default_delete<android::String16> >, std::__1::allocator<std::__1::unique_ptr<android::String16, std::__1::default_delete<android::String16> > > >, std::__1::default_delete<std::__1::vector<std::__1::unique_ptr<android::String16, std::__1::default_delete<android::String16> >, std::__1::allocator<std::__1::unique_ptr<android::String16, std::__1::default_delete<android::String16> > > > > >' does not provide a subscript operator
vector[0] = std::make_unique<String16>("310");
That worked as (*vector)[0] = std::make_unique<String16>(String16("310"));
How i was of the understanding that unique_ptr<vector<unique_ptr<String16>>>*
Allowed for setting values of null or 0 (not "0")
As this does not seem to allow null
If you're using my original snippet, elements 2, 3, 4, and 5 of the vector are null, because the vector was resized to size 6 and only the first two elements were set, so the other elements retain their values set by the default constructor of std::unique_ptr<String16> (which is null). To explicitly set an element to null:
1 2 3 4 5 6
(*vector)[whatever] = std::unique_ptr<String16>();
//or:
(*vector)[whatever].reset();
//or, to push a nullptr at the back of the vector:
vector->emplace_back();
I see now you are correct resize to 6 set values of 0 and 1 and 2, 3, 4 and 5 are not set leaving them null. Perfect you are awesome truely truely greatful