I need to get some complex data from a library then use this data at the upper level. The data consists of 2 parts: while evaluating the data A, i get some additional data B, and the data B should be returned back in the library "as is" in order to not reevaluate it again.
So to simplify this: i get data A and data B from the library, transfer both to the upper level, use A, but then i should transfer data B back to the library.
The problem is (apart from this weird architecture) i don't want my upper level to know anything about data B, so what mechanism should i use to avoid defining library-specific data types in the upper level code? Data should be passed as a pointer.
Im thinking about void*, but C++17 allows to use std::any which i dont understand quite enough. Can i use std::unique_ptr<std::any>
? Or is it just std::any
instead?
Should it be like that?
std::any GetDataAandB()
{
std::unique_ptr ret = std::make_unique<LibraryType>(1, "");
return std::make_any<std::unique_ptr<LibraryType>>( ret);
}