What tools exists today for implementing the golang package in C++? I want this to work:
import (
"fmt"
"zuzu" // my package
}
v := zuzu.Func(1,2,3)
and the zuzu.Func()
must be written in C++ as following:
// C++ code:
int Func(int a, int b, int c) {
return a + b + c;
}
Should I use the cgo ( https://golang.org/cmd/cgo/ ) to achieve this? As I understand, I must create a .go file which provides the declarations of the Func() and uses cgo
syntax to link against my .cpp / .h
files with the actual implementation?
Hard questions
Can the C++ function construct and return a non-trivial Go variables, for example the map[int]map[int]int
?
Can the C++ function return a value of a variable type? Pseudo-CPP-code:
// C++ code
// This function may return map[float32] or int.
MIXED_RETURN_TYPE cpp_func(int x) {
if ( 1 == x ) {
return MAP_OF_FLOATS; // go type: map[float32]
} else {
return 2; // go type: int
}
}