Skip to content

Commit

Permalink
enforce function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
prince-chrismc committed May 22, 2020
1 parent 659de08 commit 486102e
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions include/jwt-cpp/jwt.h
Original file line number Diff line number Diff line change
Expand Up @@ -795,34 +795,38 @@ namespace jwt {
class... Args>
struct detector
{
using value_t = std::false_type;
using value = std::false_type;
using type = Default;
};

template <class Default, template <class...> class Op, class... Args>
struct detector<Default, void_t<Op<Args...>>, Op, Args...>
{
using value_t = std::true_type;
using value = std::true_type;
using type = Op<Args...>;
};

template <template <class...> class Op, class... Args>
using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;
using is_detected = typename detector<nonesuch, void, Op, Args...>::value;

template <typename T>
using get_type_t = decltype(T::get_type);
using get_type_function = decltype(T::get_type);

template <typename T, typename value_type>
using is_get_type_signature = typename std::is_same<get_type_function<T>, json::type(const value_type&)>;

template <typename T>
using supports_get_type = is_detected<get_type_t, T>;
using supports_get_type = is_detected<get_type_function, T>;

template <typename T>
using as_object_t = decltype(T::as_object);
using as_object_function = decltype(T::as_object);
template <typename T>
using supports_as_object = is_detected<as_object_t, T>;
using supports_as_object = is_detected<as_object_function, T>;

template<typename T>
template<typename T, typename value_type>
struct is_json_traits {
static constexpr auto value =
supports_get_type<T>::value &&
supports_get_type<T>::value && is_get_type_signature<T, value_type>::value &&
supports_as_object<T>::value;
};

Expand Down Expand Up @@ -900,7 +904,7 @@ namespace jwt {
class number_type = double,
typename traits = details::picojson_traits>
class basic_claim {
static_assert(details::is_json_traits<traits>::value, "traits must satisfy is_json_traits");
static_assert(details::is_json_traits<traits, value_type>::value, "traits must satisfy is_json_traits");

value_type val;
public:
Expand Down

0 comments on commit 486102e

Please sign in to comment.