Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
910a8950
Unverified
Commit
910a8950
authored
Sep 29, 2018
by
Niels Lohmann
Committed by
GitHub
Sep 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1238 from theodelrieu/fix/1237
Fix issue #1237
parents
22e55349
1fae82b7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
140 deletions
+118
-140
type_traits.hpp
include/nlohmann/detail/meta/type_traits.hpp
+19
-5
json.hpp
include/nlohmann/json.hpp
+38
-66
json.hpp
single_include/nlohmann/json.hpp
+55
-69
unit-udt.cpp
test/src/unit-udt.cpp
+6
-0
No files found.
include/nlohmann/detail/meta/type_traits.hpp
View file @
910a8950
...
@@ -65,6 +65,9 @@ using to_json_function = decltype(T::to_json(std::declval<Args>()...));
...
@@ -65,6 +65,9 @@ using to_json_function = decltype(T::to_json(std::declval<Args>()...));
template
<
typename
T
,
typename
...
Args
>
template
<
typename
T
,
typename
...
Args
>
using
from_json_function
=
decltype
(
T
::
from_json
(
std
::
declval
<
Args
>
()...));
using
from_json_function
=
decltype
(
T
::
from_json
(
std
::
declval
<
Args
>
()...));
template
<
typename
T
,
typename
U
>
using
get_template_function
=
decltype
(
std
::
declval
<
T
>
().
template
get
<
U
>
());
///////////////////
///////////////////
// is_ functions //
// is_ functions //
///////////////////
///////////////////
...
@@ -185,8 +188,12 @@ struct is_compatible_integer_type
...
@@ -185,8 +188,12 @@ struct is_compatible_integer_type
CompatibleNumberIntegerType
>
{};
CompatibleNumberIntegerType
>
{};
// trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists
// trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists
template
<
typename
BasicJsonType
,
typename
T
>
template
<
typename
BasicJsonType
,
typename
T
,
typename
=
void
>
struct
has_from_json
struct
has_from_json
:
std
::
false_type
{};
template
<
typename
BasicJsonType
,
typename
T
>
struct
has_from_json
<
BasicJsonType
,
T
,
enable_if_t
<
not
is_basic_json
<
T
>::
value
>>
{
{
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
...
@@ -197,8 +204,11 @@ struct has_from_json
...
@@ -197,8 +204,11 @@ struct has_from_json
// 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
<
typename
BasicJsonType
,
typename
T
,
typename
=
void
>
struct
has_non_default_from_json
:
std
::
false_type
{};
template
<
typename
BasicJsonType
,
typename
T
>
template
<
typename
BasicJsonType
,
typename
T
>
struct
has_non_default_from_json
struct
has_non_default_from_json
<
BasicJsonType
,
T
,
enable_if_t
<
not
is_basic_json
<
T
>::
value
>>
{
{
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
...
@@ -208,8 +218,12 @@ struct has_non_default_from_json
...
@@ -208,8 +218,12 @@ struct has_non_default_from_json
};
};
// This trait checks if BasicJsonType::json_serializer<T>::to_json exists
// This trait checks if BasicJsonType::json_serializer<T>::to_json exists
template
<
typename
BasicJsonType
,
typename
T
>
// Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion.
struct
has_to_json
template
<
typename
BasicJsonType
,
typename
T
,
typename
=
void
>
struct
has_to_json
:
std
::
false_type
{};
template
<
typename
BasicJsonType
,
typename
T
>
struct
has_to_json
<
BasicJsonType
,
T
,
enable_if_t
<
not
is_basic_json
<
T
>::
value
>>
{
{
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
...
...
include/nlohmann/json.hpp
View file @
910a8950
...
@@ -2670,17 +2670,18 @@ class basic_json
...
@@ -2670,17 +2670,18 @@ class basic_json
/*!
/*!
@brief get a pointer value (
ex
plicit)
@brief get a pointer value (
im
plicit)
Ex
plicit pointer access to the internally stored JSON value. No copies are
Im
plicit pointer access to the internally stored JSON value. No copies are
made.
made.
@warning
The pointer becomes invalid if the underlying JSON object
@warning
Writing data to the pointee of the result yields an undefined
changes
.
state
.
@tparam PointerType pointer type; must be a pointer to @ref array_t, @ref
@tparam PointerType pointer type; must be a pointer to @ref array_t, @ref
object_t, @ref string_t, @ref boolean_t, @ref number_integer_t,
object_t, @ref string_t, @ref boolean_t, @ref number_integer_t,
@ref number_unsigned_t, or @ref number_float_t.
@ref number_unsigned_t, or @ref number_float_t. Enforced by a static
assertion.
@return pointer to the internally stored JSON value if the requested
@return pointer to the internally stored JSON value if the requested
pointer type @a PointerType fits to the JSON value; `nullptr` otherwise
pointer type @a PointerType fits to the JSON value; `nullptr` otherwise
...
@@ -2690,45 +2691,43 @@ class basic_json
...
@@ -2690,45 +2691,43 @@ class basic_json
@liveexample{The example below shows how pointers to internal values of a
@liveexample{The example below shows how pointers to internal values of a
JSON value can be requested. Note that no type conversions are made and a
JSON value can be requested. Note that no type conversions are made and a
`nullptr` is returned if the value and the requested pointer type does not
`nullptr` is returned if the value and the requested pointer type does not
match.,get__PointerType}
match.,get_ptr}
@sa @ref get_ptr() for explicit pointer-member access
@since version 1.0.0
@since version 1.0.0
*/
*/
template
<
typename
PointerType
,
typename
std
::
enable_if
<
template
<
typename
PointerType
,
typename
std
::
enable_if
<
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
PointerType
get
()
noexcept
auto
get_ptr
()
noexcept
->
decltype
(
std
::
declval
<
basic_json_t
&>
().
get_impl_ptr
(
std
::
declval
<
PointerType
>
()))
{
{
// delegate the call to get_
ptr
// delegate the call to get_
impl_ptr<>()
return
get_
ptr
<
PointerType
>
(
);
return
get_
impl_ptr
(
static_cast
<
PointerType
>
(
nullptr
)
);
}
}
/*!
/*!
@brief get a pointer value (
ex
plicit)
@brief get a pointer value (
im
plicit)
@copydoc get()
@copydoc get
_ptr
()
*/
*/
template
<
typename
PointerType
,
typename
std
::
enable_if
<
template
<
typename
PointerType
,
typename
std
::
enable_if
<
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
std
::
is_pointer
<
PointerType
>::
value
and
constexpr
const
PointerType
get
()
const
noexcept
std
::
is_const
<
typename
std
::
remove_pointer
<
PointerType
>::
type
>::
value
,
int
>::
type
=
0
>
constexpr
auto
get_ptr
()
const
noexcept
->
decltype
(
std
::
declval
<
const
basic_json_t
&>
().
get_impl_ptr
(
std
::
declval
<
PointerType
>
()))
{
{
// delegate the call to get_
ptr
// delegate the call to get_
impl_ptr<>() const
return
get_
ptr
<
PointerType
>
(
);
return
get_
impl_ptr
(
static_cast
<
PointerType
>
(
nullptr
)
);
}
}
/*!
/*!
@brief get a pointer value (
im
plicit)
@brief get a pointer value (
ex
plicit)
Im
plicit pointer access to the internally stored JSON value. No copies are
Ex
plicit pointer access to the internally stored JSON value. No copies are
made.
made.
@warning
Writing data to the pointee of the result yields an undefined
@warning
The pointer becomes invalid if the underlying JSON object
state
.
changes
.
@tparam PointerType pointer type; must be a pointer to @ref array_t, @ref
@tparam PointerType pointer type; must be a pointer to @ref array_t, @ref
object_t, @ref string_t, @ref boolean_t, @ref number_integer_t,
object_t, @ref string_t, @ref boolean_t, @ref number_integer_t,
@ref number_unsigned_t, or @ref number_float_t. Enforced by a static
@ref number_unsigned_t, or @ref number_float_t.
assertion.
@return pointer to the internally stored JSON value if the requested
@return pointer to the internally stored JSON value if the requested
pointer type @a PointerType fits to the JSON value; `nullptr` otherwise
pointer type @a PointerType fits to the JSON value; `nullptr` otherwise
...
@@ -2738,59 +2737,30 @@ class basic_json
...
@@ -2738,59 +2737,30 @@ class basic_json
@liveexample{The example below shows how pointers to internal values of a
@liveexample{The example below shows how pointers to internal values of a
JSON value can be requested. Note that no type conversions are made and a
JSON value can be requested. Note that no type conversions are made and a
`nullptr` is returned if the value and the requested pointer type does not
`nullptr` is returned if the value and the requested pointer type does not
match.,get_ptr}
match.,get__PointerType}
@sa @ref get_ptr() for explicit pointer-member access
@since version 1.0.0
@since version 1.0.0
*/
*/
template
<
typename
PointerType
,
typename
std
::
enable_if
<
template
<
typename
PointerType
,
typename
std
::
enable_if
<
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
PointerType
get_ptr
()
noexcept
auto
get
()
noexcept
->
decltype
(
std
::
declval
<
basic_json_t
&>
().
template
get_ptr
<
PointerType
>
())
{
{
// get the type of the PointerType (remove pointer and const)
// delegate the call to get_ptr
using
pointee_t
=
typename
std
::
remove_const
<
typename
return
get_ptr
<
PointerType
>
();
std
::
remove_pointer
<
typename
std
::
remove_const
<
PointerType
>::
type
>::
type
>::
type
;
// make sure the type matches the allowed types
static_assert
(
std
::
is_same
<
object_t
,
pointee_t
>::
value
or
std
::
is_same
<
array_t
,
pointee_t
>::
value
or
std
::
is_same
<
string_t
,
pointee_t
>::
value
or
std
::
is_same
<
boolean_t
,
pointee_t
>::
value
or
std
::
is_same
<
number_integer_t
,
pointee_t
>::
value
or
std
::
is_same
<
number_unsigned_t
,
pointee_t
>::
value
or
std
::
is_same
<
number_float_t
,
pointee_t
>::
value
,
"incompatible pointer type"
);
// delegate the call to get_impl_ptr<>()
return
get_impl_ptr
(
static_cast
<
PointerType
>
(
nullptr
));
}
}
/*!
/*!
@brief get a pointer value (
im
plicit)
@brief get a pointer value (
ex
plicit)
@copydoc get
_ptr
()
@copydoc get()
*/
*/
template
<
typename
PointerType
,
typename
std
::
enable_if
<
template
<
typename
PointerType
,
typename
std
::
enable_if
<
std
::
is_pointer
<
PointerType
>::
value
and
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
std
::
is_const
<
typename
std
::
remove_pointer
<
PointerType
>::
type
>::
value
,
int
>::
type
=
0
>
constexpr
auto
get
()
const
noexcept
->
decltype
(
std
::
declval
<
const
basic_json_t
&>
().
template
get_ptr
<
PointerType
>
())
constexpr
const
PointerType
get_ptr
()
const
noexcept
{
{
// delegate the call to get_ptr
// get the type of the PointerType (remove pointer and const)
return
get_ptr
<
PointerType
>
();
using
pointee_t
=
typename
std
::
remove_const
<
typename
std
::
remove_pointer
<
typename
std
::
remove_const
<
PointerType
>::
type
>::
type
>::
type
;
// make sure the type matches the allowed types
static_assert
(
std
::
is_same
<
object_t
,
pointee_t
>::
value
or
std
::
is_same
<
array_t
,
pointee_t
>::
value
or
std
::
is_same
<
string_t
,
pointee_t
>::
value
or
std
::
is_same
<
boolean_t
,
pointee_t
>::
value
or
std
::
is_same
<
number_integer_t
,
pointee_t
>::
value
or
std
::
is_same
<
number_unsigned_t
,
pointee_t
>::
value
or
std
::
is_same
<
number_float_t
,
pointee_t
>::
value
,
"incompatible pointer type"
);
// delegate the call to get_impl_ptr<>() const
return
get_impl_ptr
(
static_cast
<
PointerType
>
(
nullptr
));
}
}
/*!
/*!
...
@@ -2874,12 +2844,14 @@ class basic_json
...
@@ -2874,12 +2844,14 @@ class basic_json
not
std
::
is_same
<
ValueType
,
detail
::
json_ref
<
basic_json
>>::
value
and
not
std
::
is_same
<
ValueType
,
detail
::
json_ref
<
basic_json
>>::
value
and
not
std
::
is_same
<
ValueType
,
typename
string_t
::
value_type
>::
value
and
not
std
::
is_same
<
ValueType
,
typename
string_t
::
value_type
>::
value
and
not
detail
::
is_basic_json
<
ValueType
>::
value
not
detail
::
is_basic_json
<
ValueType
>::
value
#ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015
#ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015
and
not
std
::
is_same
<
ValueType
,
std
::
initializer_list
<
typename
string_t
::
value_type
>>::
value
and
not
std
::
is_same
<
ValueType
,
std
::
initializer_list
<
typename
string_t
::
value_type
>>::
value
#if defined(JSON_HAS_CPP_17) && defined(_MSC_VER) and _MSC_VER <= 1914
#if defined(JSON_HAS_CPP_17) && defined(_MSC_VER) and _MSC_VER <= 1914
and
not
std
::
is_same
<
ValueType
,
typename
std
::
string_view
>::
value
and
not
std
::
is_same
<
ValueType
,
typename
std
::
string_view
>::
value
#endif
#endif
#endif
#endif
and
detail
::
is_detected
<
detail
::
get_template_function
,
const
basic_json_t
&
,
ValueType
>::
value
,
int
>::
type
=
0
>
,
int
>::
type
=
0
>
operator
ValueType
()
const
operator
ValueType
()
const
{
{
...
...
single_include/nlohmann/json.hpp
View file @
910a8950
...
@@ -425,6 +425,9 @@ using to_json_function = decltype(T::to_json(std::declval<Args>()...));
...
@@ -425,6 +425,9 @@ using to_json_function = decltype(T::to_json(std::declval<Args>()...));
template
<
typename
T
,
typename
...
Args
>
template
<
typename
T
,
typename
...
Args
>
using
from_json_function
=
decltype
(
T
::
from_json
(
std
::
declval
<
Args
>
()...));
using
from_json_function
=
decltype
(
T
::
from_json
(
std
::
declval
<
Args
>
()...));
template
<
typename
T
,
typename
U
>
using
get_template_function
=
decltype
(
std
::
declval
<
T
>
().
template
get
<
U
>
());
///////////////////
///////////////////
// is_ functions //
// is_ functions //
///////////////////
///////////////////
...
@@ -545,8 +548,12 @@ struct is_compatible_integer_type
...
@@ -545,8 +548,12 @@ struct is_compatible_integer_type
CompatibleNumberIntegerType
>
{};
CompatibleNumberIntegerType
>
{};
// trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists
// trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists
template
<
typename
BasicJsonType
,
typename
T
>
template
<
typename
BasicJsonType
,
typename
T
,
typename
=
void
>
struct
has_from_json
struct
has_from_json
:
std
::
false_type
{};
template
<
typename
BasicJsonType
,
typename
T
>
struct
has_from_json
<
BasicJsonType
,
T
,
enable_if_t
<
not
is_basic_json
<
T
>::
value
>>
{
{
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
...
@@ -557,8 +564,11 @@ struct has_from_json
...
@@ -557,8 +564,11 @@ struct has_from_json
// 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
<
typename
BasicJsonType
,
typename
T
,
typename
=
void
>
struct
has_non_default_from_json
:
std
::
false_type
{};
template
<
typename
BasicJsonType
,
typename
T
>
template
<
typename
BasicJsonType
,
typename
T
>
struct
has_non_default_from_json
struct
has_non_default_from_json
<
BasicJsonType
,
T
,
enable_if_t
<
not
is_basic_json
<
T
>::
value
>>
{
{
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
...
@@ -568,8 +578,12 @@ struct has_non_default_from_json
...
@@ -568,8 +578,12 @@ struct has_non_default_from_json
};
};
// This trait checks if BasicJsonType::json_serializer<T>::to_json exists
// This trait checks if BasicJsonType::json_serializer<T>::to_json exists
template
<
typename
BasicJsonType
,
typename
T
>
// Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion.
struct
has_to_json
template
<
typename
BasicJsonType
,
typename
T
,
typename
=
void
>
struct
has_to_json
:
std
::
false_type
{};
template
<
typename
BasicJsonType
,
typename
T
>
struct
has_to_json
<
BasicJsonType
,
T
,
enable_if_t
<
not
is_basic_json
<
T
>::
value
>>
{
{
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
...
@@ -13743,17 +13757,18 @@ class basic_json
...
@@ -13743,17 +13757,18 @@ class basic_json
/*!
/*!
@brief get a pointer value (
ex
plicit)
@brief get a pointer value (
im
plicit)
Ex
plicit pointer access to the internally stored JSON value. No copies are
Im
plicit pointer access to the internally stored JSON value. No copies are
made.
made.
@warning
The pointer becomes invalid if the underlying JSON object
@warning
Writing data to the pointee of the result yields an undefined
changes
.
state
.
@tparam PointerType pointer type; must be a pointer to @ref array_t, @ref
@tparam PointerType pointer type; must be a pointer to @ref array_t, @ref
object_t, @ref string_t, @ref boolean_t, @ref number_integer_t,
object_t, @ref string_t, @ref boolean_t, @ref number_integer_t,
@ref number_unsigned_t, or @ref number_float_t.
@ref number_unsigned_t, or @ref number_float_t. Enforced by a static
assertion.
@return pointer to the internally stored JSON value if the requested
@return pointer to the internally stored JSON value if the requested
pointer type @a PointerType fits to the JSON value; `nullptr` otherwise
pointer type @a PointerType fits to the JSON value; `nullptr` otherwise
...
@@ -13763,45 +13778,43 @@ class basic_json
...
@@ -13763,45 +13778,43 @@ class basic_json
@liveexample{The example below shows how pointers to internal values of a
@liveexample{The example below shows how pointers to internal values of a
JSON value can be requested. Note that no type conversions are made and a
JSON value can be requested. Note that no type conversions are made and a
`nullptr` is returned if the value and the requested pointer type does not
`nullptr` is returned if the value and the requested pointer type does not
match.,get__PointerType}
match.,get_ptr}
@sa @ref get_ptr() for explicit pointer-member access
@since version 1.0.0
@since version 1.0.0
*/
*/
template
<
typename
PointerType
,
typename
std
::
enable_if
<
template
<
typename
PointerType
,
typename
std
::
enable_if
<
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
PointerType
get
()
noexcept
auto
get_ptr
()
noexcept
->
decltype
(
std
::
declval
<
basic_json_t
&>
().
get_impl_ptr
(
std
::
declval
<
PointerType
>
()))
{
{
// delegate the call to get_
ptr
// delegate the call to get_
impl_ptr<>()
return
get_
ptr
<
PointerType
>
(
);
return
get_
impl_ptr
(
static_cast
<
PointerType
>
(
nullptr
)
);
}
}
/*!
/*!
@brief get a pointer value (
ex
plicit)
@brief get a pointer value (
im
plicit)
@copydoc get()
@copydoc get
_ptr
()
*/
*/
template
<
typename
PointerType
,
typename
std
::
enable_if
<
template
<
typename
PointerType
,
typename
std
::
enable_if
<
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
std
::
is_pointer
<
PointerType
>::
value
and
constexpr
const
PointerType
get
()
const
noexcept
std
::
is_const
<
typename
std
::
remove_pointer
<
PointerType
>::
type
>::
value
,
int
>::
type
=
0
>
constexpr
auto
get_ptr
()
const
noexcept
->
decltype
(
std
::
declval
<
const
basic_json_t
&>
().
get_impl_ptr
(
std
::
declval
<
PointerType
>
()))
{
{
// delegate the call to get_
ptr
// delegate the call to get_
impl_ptr<>() const
return
get_
ptr
<
PointerType
>
(
);
return
get_
impl_ptr
(
static_cast
<
PointerType
>
(
nullptr
)
);
}
}
/*!
/*!
@brief get a pointer value (
im
plicit)
@brief get a pointer value (
ex
plicit)
Im
plicit pointer access to the internally stored JSON value. No copies are
Ex
plicit pointer access to the internally stored JSON value. No copies are
made.
made.
@warning
Writing data to the pointee of the result yields an undefined
@warning
The pointer becomes invalid if the underlying JSON object
state
.
changes
.
@tparam PointerType pointer type; must be a pointer to @ref array_t, @ref
@tparam PointerType pointer type; must be a pointer to @ref array_t, @ref
object_t, @ref string_t, @ref boolean_t, @ref number_integer_t,
object_t, @ref string_t, @ref boolean_t, @ref number_integer_t,
@ref number_unsigned_t, or @ref number_float_t. Enforced by a static
@ref number_unsigned_t, or @ref number_float_t.
assertion.
@return pointer to the internally stored JSON value if the requested
@return pointer to the internally stored JSON value if the requested
pointer type @a PointerType fits to the JSON value; `nullptr` otherwise
pointer type @a PointerType fits to the JSON value; `nullptr` otherwise
...
@@ -13811,59 +13824,30 @@ class basic_json
...
@@ -13811,59 +13824,30 @@ class basic_json
@liveexample{The example below shows how pointers to internal values of a
@liveexample{The example below shows how pointers to internal values of a
JSON value can be requested. Note that no type conversions are made and a
JSON value can be requested. Note that no type conversions are made and a
`nullptr` is returned if the value and the requested pointer type does not
`nullptr` is returned if the value and the requested pointer type does not
match.,get_ptr}
match.,get__PointerType}
@sa @ref get_ptr() for explicit pointer-member access
@since version 1.0.0
@since version 1.0.0
*/
*/
template
<
typename
PointerType
,
typename
std
::
enable_if
<
template
<
typename
PointerType
,
typename
std
::
enable_if
<
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
PointerType
get_ptr
()
noexcept
auto
get
()
noexcept
->
decltype
(
std
::
declval
<
basic_json_t
&>
().
template
get_ptr
<
PointerType
>
())
{
{
// get the type of the PointerType (remove pointer and const)
// delegate the call to get_ptr
using
pointee_t
=
typename
std
::
remove_const
<
typename
return
get_ptr
<
PointerType
>
();
std
::
remove_pointer
<
typename
std
::
remove_const
<
PointerType
>::
type
>::
type
>::
type
;
// make sure the type matches the allowed types
static_assert
(
std
::
is_same
<
object_t
,
pointee_t
>::
value
or
std
::
is_same
<
array_t
,
pointee_t
>::
value
or
std
::
is_same
<
string_t
,
pointee_t
>::
value
or
std
::
is_same
<
boolean_t
,
pointee_t
>::
value
or
std
::
is_same
<
number_integer_t
,
pointee_t
>::
value
or
std
::
is_same
<
number_unsigned_t
,
pointee_t
>::
value
or
std
::
is_same
<
number_float_t
,
pointee_t
>::
value
,
"incompatible pointer type"
);
// delegate the call to get_impl_ptr<>()
return
get_impl_ptr
(
static_cast
<
PointerType
>
(
nullptr
));
}
}
/*!
/*!
@brief get a pointer value (
im
plicit)
@brief get a pointer value (
ex
plicit)
@copydoc get
_ptr
()
@copydoc get()
*/
*/
template
<
typename
PointerType
,
typename
std
::
enable_if
<
template
<
typename
PointerType
,
typename
std
::
enable_if
<
std
::
is_pointer
<
PointerType
>::
value
and
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
std
::
is_const
<
typename
std
::
remove_pointer
<
PointerType
>::
type
>::
value
,
int
>::
type
=
0
>
constexpr
auto
get
()
const
noexcept
->
decltype
(
std
::
declval
<
const
basic_json_t
&>
().
template
get_ptr
<
PointerType
>
())
constexpr
const
PointerType
get_ptr
()
const
noexcept
{
{
// get the type of the PointerType (remove pointer and const)
// delegate the call to get_ptr
using
pointee_t
=
typename
std
::
remove_const
<
typename
return
get_ptr
<
PointerType
>
();
std
::
remove_pointer
<
typename
std
::
remove_const
<
PointerType
>::
type
>::
type
>::
type
;
// make sure the type matches the allowed types
static_assert
(
std
::
is_same
<
object_t
,
pointee_t
>::
value
or
std
::
is_same
<
array_t
,
pointee_t
>::
value
or
std
::
is_same
<
string_t
,
pointee_t
>::
value
or
std
::
is_same
<
boolean_t
,
pointee_t
>::
value
or
std
::
is_same
<
number_integer_t
,
pointee_t
>::
value
or
std
::
is_same
<
number_unsigned_t
,
pointee_t
>::
value
or
std
::
is_same
<
number_float_t
,
pointee_t
>::
value
,
"incompatible pointer type"
);
// delegate the call to get_impl_ptr<>() const
return
get_impl_ptr
(
static_cast
<
PointerType
>
(
nullptr
));
}
}
/*!
/*!
...
@@ -13947,12 +13931,14 @@ class basic_json
...
@@ -13947,12 +13931,14 @@ class basic_json
not
std
::
is_same
<
ValueType
,
detail
::
json_ref
<
basic_json
>>::
value
and
not
std
::
is_same
<
ValueType
,
detail
::
json_ref
<
basic_json
>>::
value
and
not
std
::
is_same
<
ValueType
,
typename
string_t
::
value_type
>::
value
and
not
std
::
is_same
<
ValueType
,
typename
string_t
::
value_type
>::
value
and
not
detail
::
is_basic_json
<
ValueType
>::
value
not
detail
::
is_basic_json
<
ValueType
>::
value
#ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015
#ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015
and
not
std
::
is_same
<
ValueType
,
std
::
initializer_list
<
typename
string_t
::
value_type
>>::
value
and
not
std
::
is_same
<
ValueType
,
std
::
initializer_list
<
typename
string_t
::
value_type
>>::
value
#if defined(JSON_HAS_CPP_17) && defined(_MSC_VER) and _MSC_VER <= 1914
#if defined(JSON_HAS_CPP_17) && defined(_MSC_VER) and _MSC_VER <= 1914
and
not
std
::
is_same
<
ValueType
,
typename
std
::
string_view
>::
value
and
not
std
::
is_same
<
ValueType
,
typename
std
::
string_view
>::
value
#endif
#endif
#endif
#endif
and
detail
::
is_detected
<
detail
::
get_template_function
,
const
basic_json_t
&
,
ValueType
>::
value
,
int
>::
type
=
0
>
,
int
>::
type
=
0
>
operator
ValueType
()
const
operator
ValueType
()
const
{
{
...
...
test/src/unit-udt.cpp
View file @
910a8950
...
@@ -824,3 +824,9 @@ TEST_CASE("Issue #924")
...
@@ -824,3 +824,9 @@ TEST_CASE("Issue #924")
CHECK_NOTHROW
(
j
.
get
<
Evil
>
());
CHECK_NOTHROW
(
j
.
get
<
Evil
>
());
CHECK_NOTHROW
(
j
.
get
<
std
::
vector
<
Evil
>>
());
CHECK_NOTHROW
(
j
.
get
<
std
::
vector
<
Evil
>>
());
}
}
TEST_CASE
(
"Issue #1237"
)
{
struct
non_convertible_type
{};
static_assert
(
not
std
::
is_convertible
<
json
,
non_convertible_type
>::
value
,
""
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment