Skip to content

Commit d7ca8d8

Browse files
wang-bincursoragent
andcommitted
detect reference_wrapper by partial specialization
is_ref_wrap previously treated any type with a nested ::type as a wrapper. Specialize on std::reference_wrapper so traits like std::decay are excluded, and keep the check C++14-friendly. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 03fb6c3 commit d7ca8d8

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎jmi.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,10 @@ struct is_jarray_cpp : integral_constant<bool, (is_array_like<T>::value || is_ar
329329
&& !is_same<typename decay<T>::type, char*>::value
330330
&& !is_same<typename decay<T>::type, const char*>::value> {};
331331

332-
template<class T, typename = void>
333-
struct is_ref_wrap :false_type{};
334-
335332
template<class T>
336-
struct is_ref_wrap<T, decltype(void(!declval<is_same<reference_wrapper<typename T::type>, remove_cvref_t<T>>>()))>: true_type{};
333+
struct is_ref_wrap : false_type {};
334+
template<class T>
335+
struct is_ref_wrap<reference_wrapper<T>> : true_type {};
337336

338337
template<typename T>
339338
using if_jarray_cpp = typename enable_if<is_jarray_cpp<T>::value, bool>::type;

‎test/signature.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ constexpr bool CstrEq(const array<char, N>& a, const char* b) {
2525
static_assert(CstrEq(jmi::signature_of<jobject>(), "Ljava/lang/Object;"), "");
2626
static_assert(CstrEq(jmi::signature_of<jstring>(), "Ljava/lang/String;"), "");
2727
static_assert(CstrEq(jmi::signature_of<jintArray>(), "[I"), "");
28+
static_assert(jmi::detail::is_ref_wrap<reference_wrapper<int>>::value, "");
29+
static_assert(!jmi::detail::is_ref_wrap<decay<int>>::value, "");
2830
extern "C" jint JNICALL JNI_OnLoad(JavaVM* vm, void*)
2931
{
3032
JNIEnv* env = nullptr;

0 commit comments

Comments
 (0)