Go
vs C++
interoperability has been discussed many times so far (here, for example), and generally it has been shown that it's possible to wrap C++
functions in C
functions, and than to wrap C
functions in CGO
functions. This is the way how to use C++
code in Go
application. However, the most of examples consider only functions with parameters of primitive data types (like int
or char *
).
But what if C++
function expects STL containers like std::vector
or std::set
to be passed? There are no equivalents for them in C
, so I have no idea what to pass from C
to C++
.
static Status GetApproximateMemoryUsageByType(
const std::vector<DB*>& dbs,
const std::unordered_set<const Cache*> cache_set,
std::map<MemoryUtil::UsageType, uint64_t>* usage_by_type);
UPD
Just for the reference, here is the example of how this problem was solved. This is a real function from RocksDB C++ API
. In order to use it in Go
, it should be wrapped in function (or several functions) that are written in C++
, but look like as just they're written in plain C
. These wrappers are compiled to library with Go
binary links against.