Hi there,
Im trying to export the std::nth_element function from cpp to nim by creating a
wrapper function like this:
{.emit:"""
#include <algorithm>
void nth_element(float* arr, int size, int n) {
std::nth_element(arr, arr + n, arr + size);
}
""".}
proc nth_element(array: ref object, size: int, n: int) {.importcpp:
"nth_element(@)".}
proc main() =
var arr = newSeq[float](10)
for i in 0 ..< arr.len:
arr[i] = i.float32
nth_element(arr, arr.len, 5)
echo arr, " ", arr[5]
main()
Run
However I have difficulty in understanding how to pass pointers between cpp and
nim. In this case I want to pass an array buffer to the nth_element function by
using any available strategy (in the example I have tried using pointers but I
did not succeeded).
Is there a way of doing that?
Thanks in advance