How to wrap a C++ class with a templated constructor

I’m trying to wrap the fastjet library in C++, using CxxWrap.
I’ve been trying to figure out how to wrap a templated constructor for this class, but I’m failing.
My attempt to just let the compiler figure this out is not met favorably. Is this currently possible? @barche

julia: /afs/desy.de/user/j/jstrube/.julia/packages/CxxWrap/Ho7vF/deps/usr/include/jlcxx/type_conversion.hpp:325: static jl_datatype_t* jlcxx::static_type_mapping<SourceT, Enable>::julia_type() [with SourceT = std::vector<fjcore::PseudoJet>; Enable = void; jl_datatype_t = _jl_datatype_t]: Assertion `type_pointer() != nullptr' failed.

signal (6): Aborted
in expression starting at /afs/desy.de/user/j/jstrube/.julia/dev/FastJet/src/FastJet.jl:9
gsignal at /lib64/libc.so.6 (unknown line)
abort at /lib64/libc.so.6 (unknown line)
__assert_fail_base at /lib64/libc.so.6 (unknown line)
__assert_fail at /lib64/libc.so.6 (unknown line)
_ZN5jlcxx19static_type_mappingISt6vectorIN6fjcore9PseudoJetESaIS3_EEvE10julia_typeEv at /afs/desy.de/user/j/jstrube/.julia/dev/FastJet/deps/usr/lib/libfastjetwrap.so (unknown line)
_ZN5jlcxx10julia_typeISt6vectorIN6fjcore9PseudoJetESaIS3_EEEEP14_jl_datatype_tv at /afs/desy.de/user/j/jstrube/.julia/dev/FastJet/deps/usr/lib/libfastjetwrap.so (unknown line)
_ZN5jlcxx6detail14argtype_vectorIJRKSt6vectorIN6fjcore9PseudoJetESaIS4_EERKNS3_13JetDefinitionEEEES2_IP14_jl_datatype_tSaISD_EEv at /afs/desy.de/user/j/jstrube/.julia/dev/FastJet/deps/usr/lib/libfastjetwrap.so (unknown line)
_ZNK5jlcxx15FunctionWrapperIP11_jl_value_tJRKSt6vectorIN6fjcore9PseudoJetESaIS5_EERKNS4_13JetDefinitionEEE14argument_typesEv at /afs/desy.de/user/j/jstrube/.julia/dev/FastJet/deps/usr/lib/libfastjetwrap.so (unknown line)
register_julia_module at /afs/desy.de/user/j/jstrube/.julia/packages/CxxWrap/jLyxA/deps/usr/lib/libcxxwrap_julia.so (unknown line)
register_julia_module at /afs/desy.de/user/j/jstrube/.julia/packages/CxxWrap/jLyxA/src/CxxWrap.jl:151 [inlined]
readmodule at /afs/desy.de/user/j/jstrube/.julia/packages/CxxWrap/jLyxA/src/CxxWrap.jl:378
wrapmodule at /afs/desy.de/user/j/jstrube/.julia/packages/CxxWrap/jLyxA/src/CxxWrap.jl:384
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1829
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2182
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:324
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:428
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:363 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:686
and so on...

A workaround is here libcxxwrap-julia/types.cpp at main · JuliaInterop/libcxxwrap-julia · GitHub .

I don’t understand how this solves my problem.
I know how to implement a method. I don’t know how to implement the templated constructor.

I guess I could write a factory method, give it some other name and just return the type…

The problem is the std::vector<PsudoJet>. You would need to either map it, since CxxWrap doesn’t (yet?) provide support for standard containers, or work around it by creating a constructor that takes an ArrayRef like the function @groot suggested. Note that in the context of issue 112 I am looking at making ArrayRef more user friendly. Also, when creating a factory method you can just name it the same as the type and it will look like an outer constructor to Julia.

Ah. Thanks for clarifying. Now that makes sense.
And thanks for the suggestion regarding the name of the factory method. I was hoping something like that would work, so I was going to try that anyway, but great that you’re confirming that.

Forgot to add in my previous message: you can decipher the types in the error like this:

c++filt -t _ZN5jlcxx19static_type_mappingISt6vectorIN6fjcore9PseudoJetESaIS3_EEvE10julia_typeEv

which yields:

jlcxx::static_type_mapping<std::vector<fjcore::PseudoJet, std::allocator<fjcore::PseudoJet> >, void>::julia_type()