Skip to content

Template class with template functions #729

@benshiffman

Description

@benshiffman

I have a rather complicated class template (using C++20 features like concepts, etc) that I have been largely successful in mapping with a few different explicit types. The issue I'm running into now is that I'm unable to map templated functions of this class.

I'd appreciate some guidance on infoMapping templated constructors, operator overloads, and other functions, assuming any of these are possible.

template <typename T>
class DLLExport Array
{
public:

    //constructors
    Array(const std::vector<size_t>& dimv);
    Array(const std::vector<size_t>& dimv, const T& val);
    Array(const std::vector<size_t>& dimv, const std::vector<T>& vals);

    Array(const Array<T>& vals);
    template <typename U> Array(const Array<U>& vals);

    Array(const T& val); 
    template <typename U> Array(const U& val);

    Array(const T* vals, const size_t& n);
    template <typename U> Array(const U* vals, const size_t& n);

    Array(Array<T>&& vals); 

    //assignment operator
    Array<T>& operator=(const Array<T>& rhs);
    template <typename U> Array<T>& operator=(const Array<U>& rhs); // requires (!std::same_as<T,U>);

    Array<T>& operator=(Array<T>&& rhs);

    template <typename U> Array<T>& operator=(const std::vector<U>& rhs);

    Array<T>& operator=(const T& rhs); 
    template <typename U> Array<T>& operator=(const U& rhs); // requires (!std::same_as<U,T>);

    //other functions have this generic format
    template <typename F> Array<F> fun(const Array<F>& in); 
    ...
}

My logic given past experience with infoMapping as well as reviewing examples in the presets repo tells me that these should work fine, but no extra code is generated:

infoMap
    .put(new Info("Array<double>::operator =<int>(const std::vector<int>& rhs)").javaNames("putVectorDouble"))
    .put(new Info("Array<double>::Array<int>(const Array<int>& vals)")
          .javaText("public ArrayDouble(@Const @ByRef ArrayInt vals) { super((Pointer)null); allocate(vals); }" +
                        "private native void allocate(@Const @ByRef ArrayInt vals);"))
    .put(new Info("Array<double>::fun<int>").javaNames("funInt"));
;

Do you see an area I'm screwing up here or is this simply not a capability of javacpp?

A side question: are destructors for pointer types automatically called by the java garbage collector? I understand how to explicitly use Pointer.deallocate() to free the memory before stuff goes out of scope because the gc isn't invoked for that situation.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions