14 ms·
To be fair, this is library FFI code so this is actually for interfacing with C++ rather than 'native' Nim. Probably not something you'd encounter unless you're
by arc776 10y ago
To be fair, this is library FFI code so this is actually for interfacing with C++ rather than 'native' Nim. Probably not something you'd encounter unless you're making a library wrapper.
And if you are doing that, worth mentioning too that Nim has a utility c2nim that automatically translates headers for FFI access.
The first line imports the C++ std::vector type and allows you to use it in Nim. To me that seems pretty good as a one liner to import a complex type from another language.
The second line is using a template to wrap the FFI call so you can use indexing operations and generic variables with the vector.
The `[]=` is describing how to write to std::vector in nim using indexing, eg; "myVec[5]=123"