I have a C++ type like:
template <typename T>
class Vector {
struct Iterator {
};
};
And in C++ I can use Iterator
as Vector<int>::Iterator
.
How do I wrap this to use it from Nim? c2nim emits
type Vector[T] {.importcpp...} = object
type Iterator[T] {.importcpp...}
which doesn't compile because nim doesn't have nested types, and would produce Vector<T>::Iterator<T>
rather than Vector<T>::Iterator
.
I can use non-nested types in Nim:
type VectorIterator[T] {.importcpp: "Vector::Iterator".}
var v : VectorIterator[cint]
And this naturally produces Vector::Iterator<int>
, which is wrong (it should be Vector<int>::Iterator
).
Is there a way to change the import specification to produce the correct output?
I've recently added the support for wrapping such nested types in the compiler. You'll need to use the latest code from the devel branch. Here is how it can be done:
{.emit: """
template <class T>
struct Vector {
struct Iterator {};
};
""".}
type
Vector {.importcpp: "Vector".} [T] = object
VectorIterator {.importcpp: "Vector<'0>::Iterator".} [T] = object
var it: VectorIterator[int]
The relevant details in the manual can be found here and here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With