diff --git a/include/jni/native_method.hpp b/include/jni/native_method.hpp index 192e301..3e41140 100644 --- a/include/jni/native_method.hpp +++ b/include/jni/native_method.hpp @@ -371,6 +371,22 @@ namespace jni methods.template operator()(field)...); } + template < class Peer, class TagType, class Initializer, class... Methods > + void RegisterNativePeer(JNIEnv& env, const Class& clazz, const char* fieldName, + Initializer initialize, + const char* initializeMethodName, + Methods&&... methods) + { + static Field field { env, clazz, fieldName }; + + using InitializerMethodType = typename NativeMethodTraits::Type; + NativePeerHelper helper; + + RegisterNatives(env, *clazz, + helper.MakeInitializer(field, initializeMethodName, initialize), + methods.template operator()(field)...); + } + // Like std::make_unique, but with non-universal reference arguments, so it can be // explicitly specialized (jni::MakePeer). template < class Peer, class... Args >