type vector* {.importc: "std::vector", header: "vector".}[T] = object
proc constructvector*[T](): vector[T] {.importcpp: "std::vector<'*0>(@)", header: "vector".}
proc push_back*[T](this: var vector[T]; x: var T) {.importcpp: "push_back", header: "vector".}
proc size*[T](this: vector[T]): csize {.noSideEffect, importcpp: "size", header: "vector".}
proc test() =
var v = constructvector[cint]()
var i: cint = 34
push_back(v, i);
echo("size: ", int(v.size()) )
test()
Compiling it I get:
config/nim.cfg(53, 2) Hint: added path: '/Users/ccm/.babel/pkgs/' [Path] config/nim.cfg(54, 2) Hint: added path: '/Users/ccm/.nimble/pkgs/compiler-0.10.3' [Path] config/nim.cfg(54, 2) Hint: added path: '/Users/ccm/.nimble/pkgs/nimble-0.6.0' [Path] config/nim.cfg(54, 2) Hint: added path: '/Users/ccm/.nimble/pkgs/c2nim-0.9.7' [Path] config/nim.cfg(54, 2) Hint: added path: '/Users/ccm/.nimble/pkgs/' [Path] Hint: used config file '/usr/local/Cellar/nimrod/HEAD/nim/config/nim.cfg' [Conf] Hint: system [Processing] Hint: testwrap [Processing] testwrap.nim(3, 58) Hint: 'T' is declared but not used [XDeclaredButNotUsed] clang++ -c -w -I/usr/local/Cellar/nimrod/HEAD/nim/lib -o /Users/ccm/development/testnim/nimcache/testwrap.o /Users/ccm/development/testnim/nimcache/testwrap.cpp /Users/ccm/development/testnim/nimcache/testwrap.cpp:71:7: error: use of class template 'std::vector' requires template arguments std::vector v = std::vector<int>(); ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:481:29: note: template is declared here class _LIBCPP_TYPE_VIS_ONLY vector ^ 1 error generated. Error: execution of an external program failed
Everything else in the generated C++ looks good and valid, it's just the declaration that's missing the template parameter. Looking in the Urhonimo example https://github.com/3dicc/Urhonimo/blob/master/examples/huge.nim I can see an use of the Urtho3D Vector class which is very similar to mine, yet the type and constructor wrappers (https://github.com/3dicc/Urhonimo/blob/master/modules/container/vector.nim) don't have any importcpp flag I'm not already using. Am I missing something?
I also tried being explicit about the type of v like this:
var v: vector[cint] = constructvector[cint]()
And it fails with the same error.I've not really used this stuff, but it seems to work if you use importcpp on the vector type
type vector* {.importcpp: "std::vector", header: "vector".}[T] = object
proc constructvector*[T](): vector[T] {.importcpp: "std::vector<'*0>(@)", header: "vector".}
proc push_back*[T](this: var vector[T]; x: var T) {.importcpp: "push_back", header: "vector".}
proc size*[T](this: vector[T]): csize {.noSideEffect, importcpp: "size", header: "vector".}
proc test() =
var v = constructvector[cint]()
var i: cint = 34
push_back(v, i);
echo("size: ", int(v.size()) )
test()