Skip to content

Non-type template with std::enable_if #491

Description

@egolearner

Our cpp code looks like this

  enum Types {
    FLOAT = 1,
    DOUBLE = 2,
    ...
  }

  template <Types T,
            typename = typename std::enable_if<T == FLOAT>::type>
  int search(const float *vec, size_t dim) {
    ...
  }

  template <Types T,
            typename = typename std::enable_if<T == DOUBLE>::type>
  int search(const double *vec, size_t dim) {
    ...
  }
        infoMap.put(new Info("Someclass::search<FLOAT>").javaNames("search"));

Javacpp will instantiate all the search functions instead of only the FLOAT one. (Subtle to us as we need all the functions.) The bigger problem is generated JNI code will call the function without template argument, leading to compiling error.

    int rval = ptr->search((const float*)ptr0, (size_t)arg1);

Relevant compiling message

candidate template ignored: couldn't infer template argument 'T'
  int search(const float *vec, size_t dim);

How to help JavaCPP generating the right calling code?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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