move type_name outside of basic_json, make it a friend
This commit is contained in:
parent
d359684f2b
commit
c833b22b7b
2 changed files with 46 additions and 40 deletions
43
src/json.hpp
43
src/json.hpp
|
@ -181,6 +181,27 @@ using is_unscoped_enum =
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
template <typename Json> std::string type_name(Json const &j)
|
||||||
|
{
|
||||||
|
switch (j.m_type)
|
||||||
|
{
|
||||||
|
case value_t::null:
|
||||||
|
return "null";
|
||||||
|
case value_t::object:
|
||||||
|
return "object";
|
||||||
|
case value_t::array:
|
||||||
|
return "array";
|
||||||
|
case value_t::string:
|
||||||
|
return "string";
|
||||||
|
case value_t::boolean:
|
||||||
|
return "boolean";
|
||||||
|
case value_t::discarded:
|
||||||
|
return "discarded";
|
||||||
|
default:
|
||||||
|
return "number";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// very useful construct against boilerplate (more boilerplate needed than in
|
// very useful construct against boilerplate (more boilerplate needed than in
|
||||||
// C++17: http://en.cppreference.com/w/cpp/types/void_t)
|
// C++17: http://en.cppreference.com/w/cpp/types/void_t)
|
||||||
template <typename...> struct make_void
|
template <typename...> struct make_void
|
||||||
|
@ -585,6 +606,7 @@ template <
|
||||||
class basic_json
|
class basic_json
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
template <typename Json> friend std::string detail::type_name(Json const &);
|
||||||
/// workaround type for MSVC
|
/// workaround type for MSVC
|
||||||
using basic_json_t = basic_json<ObjectType, ArrayType, StringType,
|
using basic_json_t = basic_json<ObjectType, ArrayType, StringType,
|
||||||
BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType,
|
BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType,
|
||||||
|
@ -8129,26 +8151,7 @@ class basic_json
|
||||||
|
|
||||||
@since version 1.0.0
|
@since version 1.0.0
|
||||||
*/
|
*/
|
||||||
std::string type_name() const
|
std::string type_name() const { return detail::type_name(*this); }
|
||||||
{
|
|
||||||
switch (m_type)
|
|
||||||
{
|
|
||||||
case value_t::null:
|
|
||||||
return "null";
|
|
||||||
case value_t::object:
|
|
||||||
return "object";
|
|
||||||
case value_t::array:
|
|
||||||
return "array";
|
|
||||||
case value_t::string:
|
|
||||||
return "string";
|
|
||||||
case value_t::boolean:
|
|
||||||
return "boolean";
|
|
||||||
case value_t::discarded:
|
|
||||||
return "discarded";
|
|
||||||
default:
|
|
||||||
return "number";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -181,6 +181,27 @@ using is_unscoped_enum =
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
template <typename Json> std::string type_name(Json const &j)
|
||||||
|
{
|
||||||
|
switch (j.m_type)
|
||||||
|
{
|
||||||
|
case value_t::null:
|
||||||
|
return "null";
|
||||||
|
case value_t::object:
|
||||||
|
return "object";
|
||||||
|
case value_t::array:
|
||||||
|
return "array";
|
||||||
|
case value_t::string:
|
||||||
|
return "string";
|
||||||
|
case value_t::boolean:
|
||||||
|
return "boolean";
|
||||||
|
case value_t::discarded:
|
||||||
|
return "discarded";
|
||||||
|
default:
|
||||||
|
return "number";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// very useful construct against boilerplate (more boilerplate needed than in
|
// very useful construct against boilerplate (more boilerplate needed than in
|
||||||
// C++17: http://en.cppreference.com/w/cpp/types/void_t)
|
// C++17: http://en.cppreference.com/w/cpp/types/void_t)
|
||||||
template <typename...> struct make_void
|
template <typename...> struct make_void
|
||||||
|
@ -586,6 +607,7 @@ template <
|
||||||
class basic_json
|
class basic_json
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
template <typename Json> friend std::string detail::type_name(Json const &);
|
||||||
/// workaround type for MSVC
|
/// workaround type for MSVC
|
||||||
using basic_json_t = basic_json<ObjectType, ArrayType, StringType,
|
using basic_json_t = basic_json<ObjectType, ArrayType, StringType,
|
||||||
BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType,
|
BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType,
|
||||||
|
@ -8127,26 +8149,7 @@ class basic_json
|
||||||
|
|
||||||
@since version 1.0.0
|
@since version 1.0.0
|
||||||
*/
|
*/
|
||||||
std::string type_name() const
|
std::string type_name() const { return detail::type_name(*this); }
|
||||||
{
|
|
||||||
switch (m_type)
|
|
||||||
{
|
|
||||||
case value_t::null:
|
|
||||||
return "null";
|
|
||||||
case value_t::object:
|
|
||||||
return "object";
|
|
||||||
case value_t::array:
|
|
||||||
return "array";
|
|
||||||
case value_t::string:
|
|
||||||
return "string";
|
|
||||||
case value_t::boolean:
|
|
||||||
return "boolean";
|
|
||||||
case value_t::discarded:
|
|
||||||
return "discarded";
|
|
||||||
default:
|
|
||||||
return "number";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*!
|
/*!
|
||||||
|
|
Loading…
Reference in a new issue