Skip to content

Commit

Permalink
Extract a helper constexpr function for templates: IsJavaClassType (#21)
Browse files Browse the repository at this point in the history
Summary:
Used in 3 places (more soon), and this is more readable.
Pull Request resolved: facebookincubator/fbjni#21

Test Plan: CI

Reviewed By: cjhopman

Differential Revision: D18138398

Pulled By: dreiss

fbshipit-source-id: 70b2a0a88ae278da3d0076fc62f6fb582001ef57
  • Loading branch information
dreiss authored and facebook-github-bot committed Oct 28, 2019
1 parent 0e5ef29 commit 0486015
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions first-party/fbjni/cxx/fbjni/detail/References.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ class JClass;

namespace detail {

template<typename T>
constexpr bool IsJavaClassType() {
return std::is_base_of<JObject, T>::value;
}

template <typename T, typename Enable = void>
struct HasJniRefRepr : std::false_type {};

Expand All @@ -146,16 +151,16 @@ struct HasJniRefRepr<T, typename std::enable_if<!std::is_same<typename T::JniRef
template <typename T>
struct RefReprType<T*> {
using type = typename std::conditional<HasJniRefRepr<T>::value, typename HasJniRefRepr<T>::type, JObjectWrapper<T*>>::type;
static_assert(std::is_base_of<JObject, type>::value,
static_assert(IsJavaClassType<type>(),
"Repr type missing JObject base.");
static_assert(std::is_same<type, typename RefReprType<type>::type>::value,
"RefReprType<T> not idempotent");
};

template <typename T>
struct RefReprType<T, typename std::enable_if<std::is_base_of<JObject, T>::value, void>::type> {
struct RefReprType<T, typename std::enable_if<IsJavaClassType<T>(), void>::type> {
using type = T;
static_assert(std::is_base_of<JObject, type>::value,
static_assert(IsJavaClassType<type>(),
"Repr type missing JObject base.");
static_assert(std::is_same<type, typename RefReprType<type>::type>::value,
"RefReprType<T> not idempotent");
Expand Down

0 comments on commit 0486015

Please sign in to comment.