If you don't need to wrap `nth_element` in C++ code, following code can be 
imported in other module and `nth_element` can accept other types.
    
    
    proc nth_element[T](first, nth, last: ptr T) {.header: "<algorithm>", 
importcpp: "std::nth_element(@)".}
    
    proc nthElement*[T](x: var openArray[T]; nth: int) =
      nth_element(x[0].addr, x[nth].addr, cast[ptr T](cast[uint](x[^1].addr) + 
sizeof(T).uint))
    
    when isMainModule:
      var x = [4, 3, 2, 1]
      
      nthElement(x, 2)
      echo x
      
      var y = [5, 4, 3, 2, 1]
      nthElement(y.toOpenArray(1, 4), 2)
      echo y
    
    Run

Reply via email to