What’s the most elegant way to return a std::list object from a shared lib function (implemented by C++ code) to a C consumer? I know for std::vector, we can return the address of the 1st element of the vector and have the consumer treat it as an array, but std::list is implemented as a linked lis.
What’s the most elegant way to return a std::list object from a shared lib
Share
Copy the
std::listto astd::vectorand return the address of the first element, as you already mentioned.(Of course, this may mean that you don’t want to be using a
std::listin the first place.)(This solution assumes that the object being accessed is owned by the C++ library — If this isn’t the case, you may need to consider allocating the memory from your C code and passing a pointer into the C++ library to copy the data.)