1

I try to use my C++ library in Java project via SWIG. But it seems that SWIG can't understand nested templates. So, this is the valid C++ code which I need to use, but SWIG can't build it:

template <template <int,template<typename>class,int> class block, int N, template<typename>class BN>
using residual = block<N,BN,1>;

I need to split it in something like this:

template <typename T> class BN;
template <int,typename BN, int> class block;
template <int N>
using residual = block<N,BN,1>;

But this is invalid C++ syntax.

So, how can I split C++ nested templates in the many non-nested templates?

konstantin_doncov
  • 2,725
  • 4
  • 40
  • 100
  • 2
    I'm curious: why are you bothering with a translator like SWIG? Why not just port your C++ code to Java, or vice versa? I would think it would be just about as fast, less of a headache ... and I'd have a LOT more confidence in the resulting code. I'm definitely curious "Why SWIG"? – paulsm4 Dec 15 '18 at 06:27
  • @paulsm4 I need to use my library with some custom dlib's functions in Java. You can check this: https://github.com/davisking/dlib/issues/1589 – konstantin_doncov Dec 15 '18 at 06:29
  • @paulsm4 I don't mind using another way(I even tried it, as you can see from the link), but I have only [this working sample](https://github.com/davisking/dlib/tree/master/dlib/java) which wraps dlib using SWIG. – konstantin_doncov Dec 15 '18 at 06:33
  • You could introduce some classes/structs, say `block1024_32_1`, where you inherit from `block<1024,32,1>` and wrap those instead. You can do this in your SWIG header. You need to create an ABI anyway. – Jens Munk Dec 23 '18 at 09:44

0 Answers0