From 0f7cecf84054a6d7305509b3d7bedc8599b0a695 Mon Sep 17 00:00:00 2001 From: Bart Janssens Date: Wed, 15 Jan 2025 07:35:15 +0100 Subject: [PATCH] Test adding a free function with template parameters --- examples/parametric.cpp | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/examples/parametric.cpp b/examples/parametric.cpp index d8a76e5..deb563b 100644 --- a/examples/parametric.cpp +++ b/examples/parametric.cpp @@ -209,6 +209,38 @@ struct WrapCppVector2 } }; +struct Unwrapped {}; + +// Type with a third template that will not be exposed to Julia +template +struct WithUnwrappedParam +{ + using value_type = T; + static constexpr int ndims = N; +}; + +// Give the unwrapped parameterr a default value +template +using UnwrappedDefault = WithUnwrappedParam; + +// Wrap the simplified type +struct WrapUnwrappedDefault +{ + template + void operator()(TypeWrapperT&& wrapped) + { + typedef typename TypeWrapperT::type WrappedT; + using value_type = typename WrappedT::value_type; + + // Constructor function that takes the types as parameters + // Call in Julia using e.g. ParametricTypes.make_unwrapped_default(ParametricTypes.P1,Val(Cint(2))) + wrapped.module().method("make_unwrapped_default", [](jlcxx::SingletonType, jlcxx::Val) + { + return WithUnwrappedParam(); + }); + } +}; + } // namespace parametric namespace jlcxx @@ -225,6 +257,12 @@ namespace jlcxx typedef ParameterList> type; }; + template + struct BuildParameterList> + { + typedef ParameterList> type; + }; + using namespace parametric; template<> struct IsMirroredType : std::false_type { }; @@ -238,6 +276,7 @@ namespace jlcxx template struct IsMirroredType> : std::false_type { }; template struct IsMirroredType> : std::false_type { }; template struct IsMirroredType> : std::false_type { }; + template struct IsMirroredType> : std::false_type { }; } // namespace jlcxx @@ -278,4 +317,8 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& types) types.add_type, TypeVar<2>>, ParameterList>>("CppVector2", jlcxx::julia_type("AbstractVector")) .apply>(WrapCppVector2()); + + types.add_type, TypeVar<2>>>("UnwrappedDefault") + .apply>(WrapUnwrappedDefault()) + .apply>(WrapUnwrappedDefault()); }