remove one has_to/from_json template parameter
This commit is contained in:
parent
5839795725
commit
29f9fe6ae9
2 changed files with 60 additions and 56 deletions
58
src/json.hpp
58
src/json.hpp
|
@ -436,7 +436,7 @@ struct is_compatible_integer_type
|
||||||
};
|
};
|
||||||
|
|
||||||
// This trait checks if JSONSerializer<T>::from_json(json const&, udt&) exists
|
// This trait checks if JSONSerializer<T>::from_json(json const&, udt&) exists
|
||||||
template <template <typename, typename> class JSONSerializer, typename Json, typename T>
|
template <typename Json, typename T>
|
||||||
struct has_from_json
|
struct has_from_json
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -448,39 +448,40 @@ struct has_from_json
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr bool value = std::is_integral<decltype(
|
static constexpr bool value = std::is_integral<decltype(
|
||||||
detect(std::declval<JSONSerializer<T, void>>()))>::value;
|
detect(std::declval<typename Json::template json_serializer<T, void>>()))>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This trait checks if JSONSerializer<T>::from_json(json const&) exists
|
// This trait checks if JSONSerializer<T>::from_json(json const&) exists
|
||||||
// this overload is used for non-default-constructible user-defined-types
|
// this overload is used for non-default-constructible user-defined-types
|
||||||
template <template <typename, typename> class JSONSerializer, typename Json,
|
template <typename Json, typename T>
|
||||||
typename T>
|
|
||||||
struct has_non_default_from_json
|
struct has_non_default_from_json
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
template <typename U, typename = enable_if_t<std::is_same<T, decltype(uncvref_t<U>::from_json(std::declval<Json>()))>::value>>
|
template <
|
||||||
static int detect(U&&);
|
typename U,
|
||||||
static void detect(...);
|
typename = enable_if_t<std::is_same<
|
||||||
|
T, decltype(uncvref_t<U>::from_json(std::declval<Json>()))>::value>>
|
||||||
|
static int detect(U &&);
|
||||||
|
static void detect(...);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr bool value = std::is_integral<decltype(
|
static constexpr bool value = std::is_integral<decltype(detect(
|
||||||
detect(std::declval<JSONSerializer<T, void>>()))>::value;
|
std::declval<typename Json::template json_serializer<T, void>>()))>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This trait checks if JSONSerializer<T>::to_json exists
|
// This trait checks if Json::json_serializer<T>::to_json exists
|
||||||
template <template <typename, typename> class JSONSerializer, typename Json,
|
template <typename Json, typename T>
|
||||||
typename T>
|
|
||||||
struct has_to_json
|
struct has_to_json
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
template <typename U, typename = decltype(uncvref_t<U>::to_json(
|
template <typename U, typename = decltype(uncvref_t<U>::to_json(
|
||||||
std::declval<Json&>(), std::declval<T>()))>
|
std::declval<Json &>(), std::declval<T>()))>
|
||||||
static int detect(U&&);
|
static int detect(U &&);
|
||||||
static void detect(...);
|
static void detect(...);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr bool value = std::is_integral<decltype(
|
static constexpr bool value = std::is_integral<decltype(detect(
|
||||||
detect(std::declval<JSONSerializer<T, void>>()))>::value;
|
std::declval<typename Json::template json_serializer<T, void>>()))>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
// overloads for basic_json template parameters
|
// overloads for basic_json template parameters
|
||||||
|
@ -900,6 +901,8 @@ class basic_json
|
||||||
template<typename U> class iter_impl;
|
template<typename U> class iter_impl;
|
||||||
template<typename Base> class json_reverse_iterator;
|
template<typename Base> class json_reverse_iterator;
|
||||||
class json_pointer;
|
class json_pointer;
|
||||||
|
template <typename T, typename SFINAE>
|
||||||
|
using json_serializer = JSONSerializer<T, SFINAE>;
|
||||||
|
|
||||||
/////////////////////
|
/////////////////////
|
||||||
// container types //
|
// container types //
|
||||||
|
@ -1790,7 +1793,7 @@ class basic_json
|
||||||
not std::is_base_of<std::istream, U>::value and
|
not std::is_base_of<std::istream, U>::value and
|
||||||
not std::is_same<U, basic_json_t>::value and
|
not std::is_same<U, basic_json_t>::value and
|
||||||
not detail::is_basic_json_nested_type<basic_json_t,U>::value and
|
not detail::is_basic_json_nested_type<basic_json_t,U>::value and
|
||||||
detail::has_to_json<JSONSerializer, basic_json, U>::value,
|
detail::has_to_json<basic_json, U>::value,
|
||||||
int> = 0>
|
int> = 0>
|
||||||
basic_json(T &&val)
|
basic_json(T &&val)
|
||||||
{
|
{
|
||||||
|
@ -2957,10 +2960,9 @@ class basic_json
|
||||||
template <
|
template <
|
||||||
typename T,
|
typename T,
|
||||||
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
|
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
|
||||||
detail::has_from_json<JSONSerializer, basic_json_t,
|
detail::has_from_json<basic_json_t, uncvref_t<T>>::value and
|
||||||
uncvref_t<T>>::value and
|
|
||||||
not detail::has_non_default_from_json<
|
not detail::has_non_default_from_json<
|
||||||
JSONSerializer, basic_json_t, uncvref_t<T>>::value,
|
basic_json_t, uncvref_t<T>>::value,
|
||||||
int> = 0>
|
int> = 0>
|
||||||
// do we really want the uncvref ? if a user call get<int &>, shouldn't we
|
// do we really want the uncvref ? if a user call get<int &>, shouldn't we
|
||||||
// static assert ?
|
// static assert ?
|
||||||
|
@ -2983,8 +2985,8 @@ class basic_json
|
||||||
template <
|
template <
|
||||||
typename T,
|
typename T,
|
||||||
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
|
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
|
||||||
detail::has_non_default_from_json<
|
detail::has_non_default_from_json<basic_json_t,
|
||||||
JSONSerializer, basic_json_t, uncvref_t<T>>::value,
|
uncvref_t<T>>::value,
|
||||||
int> = 0>
|
int> = 0>
|
||||||
uncvref_t<T> get() const
|
uncvref_t<T> get() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -436,7 +436,7 @@ struct is_compatible_integer_type
|
||||||
};
|
};
|
||||||
|
|
||||||
// This trait checks if JSONSerializer<T>::from_json(json const&, udt&) exists
|
// This trait checks if JSONSerializer<T>::from_json(json const&, udt&) exists
|
||||||
template <template <typename, typename> class JSONSerializer, typename Json, typename T>
|
template <typename Json, typename T>
|
||||||
struct has_from_json
|
struct has_from_json
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -448,39 +448,40 @@ struct has_from_json
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr bool value = std::is_integral<decltype(
|
static constexpr bool value = std::is_integral<decltype(
|
||||||
detect(std::declval<JSONSerializer<T, void>>()))>::value;
|
detect(std::declval<typename Json::template json_serializer<T, void>>()))>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This trait checks if JSONSerializer<T>::from_json(json const&) exists
|
// This trait checks if JSONSerializer<T>::from_json(json const&) exists
|
||||||
// this overload is used for non-default-constructible user-defined-types
|
// this overload is used for non-default-constructible user-defined-types
|
||||||
template <template <typename, typename> class JSONSerializer, typename Json,
|
template <typename Json, typename T>
|
||||||
typename T>
|
|
||||||
struct has_non_default_from_json
|
struct has_non_default_from_json
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
template <typename U, typename = enable_if_t<std::is_same<T, decltype(uncvref_t<U>::from_json(std::declval<Json>()))>::value>>
|
template <
|
||||||
static int detect(U&&);
|
typename U,
|
||||||
static void detect(...);
|
typename = enable_if_t<std::is_same<
|
||||||
|
T, decltype(uncvref_t<U>::from_json(std::declval<Json>()))>::value>>
|
||||||
|
static int detect(U &&);
|
||||||
|
static void detect(...);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr bool value = std::is_integral<decltype(
|
static constexpr bool value = std::is_integral<decltype(detect(
|
||||||
detect(std::declval<JSONSerializer<T, void>>()))>::value;
|
std::declval<typename Json::template json_serializer<T, void>>()))>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This trait checks if JSONSerializer<T>::to_json exists
|
// This trait checks if Json::json_serializer<T>::to_json exists
|
||||||
template <template <typename, typename> class JSONSerializer, typename Json,
|
template <typename Json, typename T>
|
||||||
typename T>
|
|
||||||
struct has_to_json
|
struct has_to_json
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
template <typename U, typename = decltype(uncvref_t<U>::to_json(
|
template <typename U, typename = decltype(uncvref_t<U>::to_json(
|
||||||
std::declval<Json&>(), std::declval<T>()))>
|
std::declval<Json &>(), std::declval<T>()))>
|
||||||
static int detect(U&&);
|
static int detect(U &&);
|
||||||
static void detect(...);
|
static void detect(...);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr bool value = std::is_integral<decltype(
|
static constexpr bool value = std::is_integral<decltype(detect(
|
||||||
detect(std::declval<JSONSerializer<T, void>>()))>::value;
|
std::declval<typename Json::template json_serializer<T, void>>()))>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
// overloads for basic_json template parameters
|
// overloads for basic_json template parameters
|
||||||
|
@ -900,6 +901,8 @@ class basic_json
|
||||||
template<typename U> class iter_impl;
|
template<typename U> class iter_impl;
|
||||||
template<typename Base> class json_reverse_iterator;
|
template<typename Base> class json_reverse_iterator;
|
||||||
class json_pointer;
|
class json_pointer;
|
||||||
|
template <typename T, typename SFINAE>
|
||||||
|
using json_serializer = JSONSerializer<T, SFINAE>;
|
||||||
|
|
||||||
/////////////////////
|
/////////////////////
|
||||||
// container types //
|
// container types //
|
||||||
|
@ -1790,7 +1793,7 @@ class basic_json
|
||||||
not std::is_base_of<std::istream, U>::value and
|
not std::is_base_of<std::istream, U>::value and
|
||||||
not std::is_same<U, basic_json_t>::value and
|
not std::is_same<U, basic_json_t>::value and
|
||||||
not detail::is_basic_json_nested_type<basic_json_t,U>::value and
|
not detail::is_basic_json_nested_type<basic_json_t,U>::value and
|
||||||
detail::has_to_json<JSONSerializer, basic_json, U>::value,
|
detail::has_to_json<basic_json, U>::value,
|
||||||
int> = 0>
|
int> = 0>
|
||||||
basic_json(T &&val)
|
basic_json(T &&val)
|
||||||
{
|
{
|
||||||
|
@ -2957,10 +2960,9 @@ class basic_json
|
||||||
template <
|
template <
|
||||||
typename T,
|
typename T,
|
||||||
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
|
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
|
||||||
detail::has_from_json<JSONSerializer, basic_json_t,
|
detail::has_from_json<basic_json_t, uncvref_t<T>>::value and
|
||||||
uncvref_t<T>>::value and
|
|
||||||
not detail::has_non_default_from_json<
|
not detail::has_non_default_from_json<
|
||||||
JSONSerializer, basic_json_t, uncvref_t<T>>::value,
|
basic_json_t, uncvref_t<T>>::value,
|
||||||
int> = 0>
|
int> = 0>
|
||||||
// do we really want the uncvref ? if a user call get<int &>, shouldn't we
|
// do we really want the uncvref ? if a user call get<int &>, shouldn't we
|
||||||
// static assert ?
|
// static assert ?
|
||||||
|
@ -2983,8 +2985,8 @@ class basic_json
|
||||||
template <
|
template <
|
||||||
typename T,
|
typename T,
|
||||||
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
|
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
|
||||||
detail::has_non_default_from_json<
|
detail::has_non_default_from_json<basic_json_t,
|
||||||
JSONSerializer, basic_json_t, uncvref_t<T>>::value,
|
uncvref_t<T>>::value,
|
||||||
int> = 0>
|
int> = 0>
|
||||||
uncvref_t<T> get() const
|
uncvref_t<T> get() const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue