diff --git a/packages/react-native-nitro-modules/android/src/main/cpp/utils/JNISharedPtr.hpp b/packages/react-native-nitro-modules/android/src/main/cpp/utils/JNISharedPtr.hpp index aa71a2435..9214a90f5 100644 --- a/packages/react-native-nitro-modules/android/src/main/cpp/utils/JNISharedPtr.hpp +++ b/packages/react-native-nitro-modules/android/src/main/cpp/utils/JNISharedPtr.hpp @@ -53,7 +53,8 @@ class JNISharedPtr final { * each time. It is not safe to call this multiple times if you use enable_shared_from_this. * Instead, use HybridObject::shared(). */ - template ::value, int>::type = 0> + template + requires is_base_template_of::value static std::shared_ptr make_shared_from_jni(const jni::global_ref& ref) { #ifdef NITRO_DEBUG if (ref == nullptr || ref->cthis() == nullptr) [[unlikely]] { diff --git a/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+ArrayBuffer.hpp b/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+ArrayBuffer.hpp index af97a1e53..99c4367ad 100644 --- a/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+ArrayBuffer.hpp +++ b/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+ArrayBuffer.hpp @@ -21,7 +21,6 @@ struct JSIConverter; #include "NitroDefines.hpp" #include #include -#include namespace margelo::nitro { @@ -35,7 +34,8 @@ struct MutableBufferNativeState final : public jsi::NativeState { // MutableBuffer <> ArrayBuffer template -struct JSIConverter>> final { + requires SharedPtrTo +struct JSIConverter final { static inline std::shared_ptr fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { #ifdef NITRO_DEBUG if (!arg.isObject()) [[unlikely]] { diff --git a/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+HostObject.hpp b/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+HostObject.hpp index 462e7c3dd..a2fc62b6e 100644 --- a/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+HostObject.hpp +++ b/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+HostObject.hpp @@ -8,7 +8,6 @@ #include "NitroDefines.hpp" #include "NitroTypeInfo.hpp" #include -#include namespace margelo::nitro { @@ -16,7 +15,8 @@ using namespace facebook; // jsi::HostObject <> {} template -struct JSIConverter>> final { + requires SharedPtrTo +struct JSIConverter final { using TPointee = typename T::element_type; static inline T fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { diff --git a/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+NativeState.hpp b/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+NativeState.hpp index 816054682..598ae563a 100644 --- a/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+NativeState.hpp +++ b/packages/react-native-nitro-modules/cpp/jsi/JSIConverter+NativeState.hpp @@ -12,7 +12,6 @@ class HybridObject; #include "NitroDefines.hpp" #include "NitroTypeInfo.hpp" #include -#include namespace margelo::nitro { @@ -20,7 +19,8 @@ using namespace facebook; // NativeState <> {} template -struct JSIConverter>> final { + requires SharedPtrTo +struct JSIConverter final { using TPointee = typename T::element_type; static inline T fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { diff --git a/packages/react-native-nitro-modules/cpp/templates/IsSharedPtrTo.hpp b/packages/react-native-nitro-modules/cpp/templates/IsSharedPtrTo.hpp index 9ba0987dc..bc8dbfa85 100644 --- a/packages/react-native-nitro-modules/cpp/templates/IsSharedPtrTo.hpp +++ b/packages/react-native-nitro-modules/cpp/templates/IsSharedPtrTo.hpp @@ -7,12 +7,11 @@ #pragma once +#include #include namespace margelo::nitro { -using namespace facebook; - // Returns whether the given type T is a shared_ptr to type P. template struct is_shared_ptr_to : std::false_type {}; @@ -24,4 +23,7 @@ struct is_shared_ptr_to, P> : std::is_base_of constexpr bool is_shared_ptr_to_v = is_shared_ptr_to::value; +template +concept SharedPtrTo = is_shared_ptr_to_v; + } // namespace margelo::nitro