How to use autocxx with C++ function and class templates?

I am very new to C++ and am trying to wrapping a C++ codebase at GitHub - NVIDIA/MatX: An efficient C++17 GPU numerical computing library with Python-like syntax. It has a class that looks like

template <typename T,
          int RANK,
          typename Storage = DefaultStorage<T>,
          typename Desc = DefaultDescriptor<RANK>>
class tensor_t : public detail::tensor_impl_t<T,RANK,Desc>

and a make_tensor function

template <typename T, int RANK>
auto make_tensor( const index_t (&shape)[RANK],
                  matxMemorySpace_t space = MATX_MANAGED_MEMORY,
                  cudaStream_t stream = 0)

to create the tensor. In C++, I have a minimal function

matx::tensor_t<float, 2> make_f32_2d() {
    auto x = matx::make_tensor<float>({2, 3});
    return x;

but in the autocxx generated Rust code, this function is created as a pub struct make_f32_2d. The doc message is autocxx bindings couldn't be generated: This function or method uses a type where one of the template parameters was incomprehensible to bindgen/autocxx - probably because it uses template specialization.

How should I work around template specialization problem? Thanks!

it's not just a template specialization problem. these kind of C++ libraries (I would say, almost all "header-only" C++ libraries) are generally not good candidates to create "bindings" for. they rely heavily on C++ advanced template meta programming techniques, in order to create some flavor of embedded DSL in C++. they cannot be easily mimicked in non-C++ languages, and even if you managed to translate them, the syntax probably would not be as pleasant to use as the original C++ API, defeating the purpose of a fluent DSL.

tools like bindgen or autocxx generally generate bindings from C/C++ interface (structs, unions, enums, functions, constants, etc) declarations, but for code that is mostly template meta programming, the tool must parse and understand the full semantics of the C++ templates and rewrite them into rust, which is practically impossible. many C++ TMP patterns cannot be translated even by human.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.