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
21881606
Unverified
Commit
21881606
authored
Aug 14, 2017
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add detail/conversions/to_json.hpp
parent
e0c02c14
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
340 additions
and
322 deletions
+340
-322
Makefile
Makefile
+2
-1
to_json.hpp
src/detail/conversions/to_json.hpp
+337
-0
json.hpp
src/json.hpp
+1
-321
No files found.
Makefile
View file @
21881606
...
@@ -8,7 +8,8 @@ SRCS = ${SRCDIR}/json.hpp \
...
@@ -8,7 +8,8 @@ SRCS = ${SRCDIR}/json.hpp \
${
SRCDIR
}
/detail/meta.hpp
\
${
SRCDIR
}
/detail/meta.hpp
\
${
SRCDIR
}
/detail/exceptions.hpp
\
${
SRCDIR
}
/detail/exceptions.hpp
\
${
SRCDIR
}
/detail/value_t.hpp
\
${
SRCDIR
}
/detail/value_t.hpp
\
${
SRCDIR
}
/detail/conversions/from_json.hpp
${
SRCDIR
}
/detail/conversions/from_json.hpp
\
${
SRCDIR
}
/detail/conversions/to_json.hpp
...
...
src/detail/conversions/to_json.hpp
0 → 100644
View file @
21881606
#ifndef NLOHMANN_JSON_DETAIL_CONVERSIONS_TO_JSON_HPP
#define NLOHMANN_JSON_DETAIL_CONVERSIONS_TO_JSON_HPP
#include <type_traits>
#include <utility>
#include <valarray>
#include "detail/meta.hpp"
#include "detail/value_t.hpp"
namespace
nlohmann
{
namespace
detail
{
//////////////////
// constructors //
//////////////////
template
<
value_t
>
struct
external_constructor
;
template
<>
struct
external_constructor
<
value_t
::
boolean
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
boolean_t
b
)
noexcept
{
j
.
m_type
=
value_t
::
boolean
;
j
.
m_value
=
b
;
j
.
assert_invariant
();
}
};
template
<>
struct
external_constructor
<
value_t
::
string
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
const
typename
BasicJsonType
::
string_t
&
s
)
{
j
.
m_type
=
value_t
::
string
;
j
.
m_value
=
s
;
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
string_t
&&
s
)
{
j
.
m_type
=
value_t
::
string
;
j
.
m_value
=
std
::
move
(
s
);
j
.
assert_invariant
();
}
};
template
<>
struct
external_constructor
<
value_t
::
number_float
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
number_float_t
val
)
noexcept
{
j
.
m_type
=
value_t
::
number_float
;
j
.
m_value
=
val
;
j
.
assert_invariant
();
}
};
template
<>
struct
external_constructor
<
value_t
::
number_unsigned
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
number_unsigned_t
val
)
noexcept
{
j
.
m_type
=
value_t
::
number_unsigned
;
j
.
m_value
=
val
;
j
.
assert_invariant
();
}
};
template
<>
struct
external_constructor
<
value_t
::
number_integer
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
number_integer_t
val
)
noexcept
{
j
.
m_type
=
value_t
::
number_integer
;
j
.
m_value
=
val
;
j
.
assert_invariant
();
}
};
template
<>
struct
external_constructor
<
value_t
::
array
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
const
typename
BasicJsonType
::
array_t
&
arr
)
{
j
.
m_type
=
value_t
::
array
;
j
.
m_value
=
arr
;
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
array_t
&&
arr
)
{
j
.
m_type
=
value_t
::
array
;
j
.
m_value
=
std
::
move
(
arr
);
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
,
typename
CompatibleArrayType
,
enable_if_t
<
not
std
::
is_same
<
CompatibleArrayType
,
typename
BasicJsonType
::
array_t
>::
value
,
int
>
=
0
>
static
void
construct
(
BasicJsonType
&
j
,
const
CompatibleArrayType
&
arr
)
{
using
std
::
begin
;
using
std
::
end
;
j
.
m_type
=
value_t
::
array
;
j
.
m_value
.
array
=
j
.
template
create
<
typename
BasicJsonType
::
array_t
>
(
begin
(
arr
),
end
(
arr
));
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
const
std
::
vector
<
bool
>&
arr
)
{
j
.
m_type
=
value_t
::
array
;
j
.
m_value
=
value_t
::
array
;
j
.
m_value
.
array
->
reserve
(
arr
.
size
());
for
(
const
bool
x
:
arr
)
{
j
.
m_value
.
array
->
push_back
(
x
);
}
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
,
typename
T
,
enable_if_t
<
std
::
is_convertible
<
T
,
BasicJsonType
>::
value
,
int
>
=
0
>
static
void
construct
(
BasicJsonType
&
j
,
const
std
::
valarray
<
T
>&
arr
)
{
j
.
m_type
=
value_t
::
array
;
j
.
m_value
=
value_t
::
array
;
j
.
m_value
.
array
->
resize
(
arr
.
size
());
std
::
copy
(
std
::
begin
(
arr
),
std
::
end
(
arr
),
j
.
m_value
.
array
->
begin
());
j
.
assert_invariant
();
}
};
template
<>
struct
external_constructor
<
value_t
::
object
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
const
typename
BasicJsonType
::
object_t
&
obj
)
{
j
.
m_type
=
value_t
::
object
;
j
.
m_value
=
obj
;
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
object_t
&&
obj
)
{
j
.
m_type
=
value_t
::
object
;
j
.
m_value
=
std
::
move
(
obj
);
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
,
typename
CompatibleObjectType
,
enable_if_t
<
not
std
::
is_same
<
CompatibleObjectType
,
typename
BasicJsonType
::
object_t
>::
value
,
int
>
=
0
>
static
void
construct
(
BasicJsonType
&
j
,
const
CompatibleObjectType
&
obj
)
{
using
std
::
begin
;
using
std
::
end
;
j
.
m_type
=
value_t
::
object
;
j
.
m_value
.
object
=
j
.
template
create
<
typename
BasicJsonType
::
object_t
>
(
begin
(
obj
),
end
(
obj
));
j
.
assert_invariant
();
}
};
/////////////
// to_json //
/////////////
template
<
typename
BasicJsonType
,
typename
T
,
enable_if_t
<
std
::
is_same
<
T
,
typename
BasicJsonType
::
boolean_t
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
T
b
)
noexcept
{
external_constructor
<
value_t
::
boolean
>::
construct
(
j
,
b
);
}
template
<
typename
BasicJsonType
,
typename
CompatibleString
,
enable_if_t
<
std
::
is_constructible
<
typename
BasicJsonType
::
string_t
,
CompatibleString
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
const
CompatibleString
&
s
)
{
external_constructor
<
value_t
::
string
>::
construct
(
j
,
s
);
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
string_t
&&
s
)
{
external_constructor
<
value_t
::
string
>::
construct
(
j
,
std
::
move
(
s
));
}
template
<
typename
BasicJsonType
,
typename
FloatType
,
enable_if_t
<
std
::
is_floating_point
<
FloatType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
FloatType
val
)
noexcept
{
external_constructor
<
value_t
::
number_float
>::
construct
(
j
,
static_cast
<
typename
BasicJsonType
::
number_float_t
>
(
val
));
}
template
<
typename
BasicJsonType
,
typename
CompatibleNumberUnsignedType
,
enable_if_t
<
is_compatible_integer_type
<
typename
BasicJsonType
::
number_unsigned_t
,
CompatibleNumberUnsignedType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
CompatibleNumberUnsignedType
val
)
noexcept
{
external_constructor
<
value_t
::
number_unsigned
>::
construct
(
j
,
static_cast
<
typename
BasicJsonType
::
number_unsigned_t
>
(
val
));
}
template
<
typename
BasicJsonType
,
typename
CompatibleNumberIntegerType
,
enable_if_t
<
is_compatible_integer_type
<
typename
BasicJsonType
::
number_integer_t
,
CompatibleNumberIntegerType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
CompatibleNumberIntegerType
val
)
noexcept
{
external_constructor
<
value_t
::
number_integer
>::
construct
(
j
,
static_cast
<
typename
BasicJsonType
::
number_integer_t
>
(
val
));
}
template
<
typename
BasicJsonType
,
typename
EnumType
,
enable_if_t
<
std
::
is_enum
<
EnumType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
EnumType
e
)
noexcept
{
using
underlying_type
=
typename
std
::
underlying_type
<
EnumType
>::
type
;
external_constructor
<
value_t
::
number_integer
>::
construct
(
j
,
static_cast
<
underlying_type
>
(
e
));
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
const
std
::
vector
<
bool
>&
e
)
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
e
);
}
template
<
typename
BasicJsonType
,
typename
CompatibleArrayType
,
enable_if_t
<
is_compatible_array_type
<
BasicJsonType
,
CompatibleArrayType
>::
value
or
std
::
is_same
<
typename
BasicJsonType
::
array_t
,
CompatibleArrayType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
const
CompatibleArrayType
&
arr
)
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
arr
);
}
template
<
typename
BasicJsonType
,
typename
T
,
enable_if_t
<
std
::
is_convertible
<
T
,
BasicJsonType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
std
::
valarray
<
T
>
arr
)
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
std
::
move
(
arr
));
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
array_t
&&
arr
)
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
std
::
move
(
arr
));
}
template
<
typename
BasicJsonType
,
typename
CompatibleObjectType
,
enable_if_t
<
is_compatible_object_type
<
BasicJsonType
,
CompatibleObjectType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
const
CompatibleObjectType
&
obj
)
{
external_constructor
<
value_t
::
object
>::
construct
(
j
,
obj
);
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
object_t
&&
obj
)
{
external_constructor
<
value_t
::
object
>::
construct
(
j
,
std
::
move
(
obj
));
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
,
enable_if_t
<
not
std
::
is_constructible
<
typename
BasicJsonType
::
string_t
,
T
(
&
)[
N
]
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
T
(
&
arr
)[
N
])
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
arr
);
}
template
<
typename
BasicJsonType
,
typename
...
Args
>
void
to_json
(
BasicJsonType
&
j
,
const
std
::
pair
<
Args
...
>&
p
)
{
j
=
{
p
.
first
,
p
.
second
};
}
template
<
typename
BasicJsonType
,
typename
Tuple
,
std
::
size_t
...
Idx
>
void
to_json_tuple_impl
(
BasicJsonType
&
j
,
const
Tuple
&
t
,
index_sequence
<
Idx
...
>
)
{
j
=
{
std
::
get
<
Idx
>
(
t
)...};
}
template
<
typename
BasicJsonType
,
typename
...
Args
>
void
to_json
(
BasicJsonType
&
j
,
const
std
::
tuple
<
Args
...
>&
t
)
{
to_json_tuple_impl
(
j
,
t
,
index_sequence_for
<
Args
...
>
{});
}
struct
to_json_fn
{
private
:
template
<
typename
BasicJsonType
,
typename
T
>
auto
call
(
BasicJsonType
&
j
,
T
&&
val
,
priority_tag
<
1
>
/*unused*/
)
const
noexcept
(
noexcept
(
to_json
(
j
,
std
::
forward
<
T
>
(
val
))))
->
decltype
(
to_json
(
j
,
std
::
forward
<
T
>
(
val
)),
void
())
{
return
to_json
(
j
,
std
::
forward
<
T
>
(
val
));
}
template
<
typename
BasicJsonType
,
typename
T
>
void
call
(
BasicJsonType
&
/*unused*/
,
T
&&
/*unused*/
,
priority_tag
<
0
>
/*unused*/
)
const
noexcept
{
static_assert
(
sizeof
(
BasicJsonType
)
==
0
,
"could not find to_json() method in T's namespace"
);
#ifdef _MSC_VER
// MSVC does not show a stacktrace for the above assert
using
decayed
=
uncvref_t
<
T
>
;
static_assert
(
sizeof
(
typename
decayed
::
force_msvc_stacktrace
)
==
0
,
"forcing MSVC stacktrace to show which T we're talking about."
);
#endif
}
public
:
template
<
typename
BasicJsonType
,
typename
T
>
void
operator
()(
BasicJsonType
&
j
,
T
&&
val
)
const
noexcept
(
noexcept
(
std
::
declval
<
to_json_fn
>
().
call
(
j
,
std
::
forward
<
T
>
(
val
),
priority_tag
<
1
>
{})))
{
return
call
(
j
,
std
::
forward
<
T
>
(
val
),
priority_tag
<
1
>
{});
}
};
}
/// namespace to hold default `to_json` function
namespace
{
constexpr
const
auto
&
to_json
=
detail
::
static_const
<
detail
::
to_json_fn
>::
value
;
}
}
#endif
src/json.hpp
View file @
21881606
...
@@ -49,7 +49,6 @@ SOFTWARE.
...
@@ -49,7 +49,6 @@ SOFTWARE.
#include <numeric> // accumulate
#include <numeric> // accumulate
#include <sstream> // stringstream
#include <sstream> // stringstream
#include <utility> // declval, forward, make_pair, move, pair, swap
#include <utility> // declval, forward, make_pair, move, pair, swap
#include <valarray> // valarray
#include "json_fwd.hpp"
#include "json_fwd.hpp"
#include "detail/macro_scope.hpp"
#include "detail/macro_scope.hpp"
...
@@ -57,6 +56,7 @@ SOFTWARE.
...
@@ -57,6 +56,7 @@ SOFTWARE.
#include "detail/exceptions.hpp"
#include "detail/exceptions.hpp"
#include "detail/value_t.hpp"
#include "detail/value_t.hpp"
#include "detail/conversions/from_json.hpp"
#include "detail/conversions/from_json.hpp"
#include "detail/conversions/to_json.hpp"
/*!
/*!
@brief namespace for Niels Lohmann
@brief namespace for Niels Lohmann
...
@@ -67,320 +67,6 @@ namespace nlohmann
...
@@ -67,320 +67,6 @@ namespace nlohmann
{
{
namespace
detail
namespace
detail
{
{
//////////////////
// constructors //
//////////////////
template
<
value_t
>
struct
external_constructor
;
template
<>
struct
external_constructor
<
value_t
::
boolean
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
boolean_t
b
)
noexcept
{
j
.
m_type
=
value_t
::
boolean
;
j
.
m_value
=
b
;
j
.
assert_invariant
();
}
};
template
<>
struct
external_constructor
<
value_t
::
string
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
const
typename
BasicJsonType
::
string_t
&
s
)
{
j
.
m_type
=
value_t
::
string
;
j
.
m_value
=
s
;
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
string_t
&&
s
)
{
j
.
m_type
=
value_t
::
string
;
j
.
m_value
=
std
::
move
(
s
);
j
.
assert_invariant
();
}
};
template
<>
struct
external_constructor
<
value_t
::
number_float
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
number_float_t
val
)
noexcept
{
j
.
m_type
=
value_t
::
number_float
;
j
.
m_value
=
val
;
j
.
assert_invariant
();
}
};
template
<>
struct
external_constructor
<
value_t
::
number_unsigned
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
number_unsigned_t
val
)
noexcept
{
j
.
m_type
=
value_t
::
number_unsigned
;
j
.
m_value
=
val
;
j
.
assert_invariant
();
}
};
template
<>
struct
external_constructor
<
value_t
::
number_integer
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
number_integer_t
val
)
noexcept
{
j
.
m_type
=
value_t
::
number_integer
;
j
.
m_value
=
val
;
j
.
assert_invariant
();
}
};
template
<>
struct
external_constructor
<
value_t
::
array
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
const
typename
BasicJsonType
::
array_t
&
arr
)
{
j
.
m_type
=
value_t
::
array
;
j
.
m_value
=
arr
;
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
array_t
&&
arr
)
{
j
.
m_type
=
value_t
::
array
;
j
.
m_value
=
std
::
move
(
arr
);
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
,
typename
CompatibleArrayType
,
enable_if_t
<
not
std
::
is_same
<
CompatibleArrayType
,
typename
BasicJsonType
::
array_t
>::
value
,
int
>
=
0
>
static
void
construct
(
BasicJsonType
&
j
,
const
CompatibleArrayType
&
arr
)
{
using
std
::
begin
;
using
std
::
end
;
j
.
m_type
=
value_t
::
array
;
j
.
m_value
.
array
=
j
.
template
create
<
typename
BasicJsonType
::
array_t
>
(
begin
(
arr
),
end
(
arr
));
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
const
std
::
vector
<
bool
>&
arr
)
{
j
.
m_type
=
value_t
::
array
;
j
.
m_value
=
value_t
::
array
;
j
.
m_value
.
array
->
reserve
(
arr
.
size
());
for
(
const
bool
x
:
arr
)
{
j
.
m_value
.
array
->
push_back
(
x
);
}
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
,
typename
T
,
enable_if_t
<
std
::
is_convertible
<
T
,
BasicJsonType
>::
value
,
int
>
=
0
>
static
void
construct
(
BasicJsonType
&
j
,
const
std
::
valarray
<
T
>&
arr
)
{
j
.
m_type
=
value_t
::
array
;
j
.
m_value
=
value_t
::
array
;
j
.
m_value
.
array
->
resize
(
arr
.
size
());
std
::
copy
(
std
::
begin
(
arr
),
std
::
end
(
arr
),
j
.
m_value
.
array
->
begin
());
j
.
assert_invariant
();
}
};
template
<>
struct
external_constructor
<
value_t
::
object
>
{
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
const
typename
BasicJsonType
::
object_t
&
obj
)
{
j
.
m_type
=
value_t
::
object
;
j
.
m_value
=
obj
;
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
>
static
void
construct
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
object_t
&&
obj
)
{
j
.
m_type
=
value_t
::
object
;
j
.
m_value
=
std
::
move
(
obj
);
j
.
assert_invariant
();
}
template
<
typename
BasicJsonType
,
typename
CompatibleObjectType
,
enable_if_t
<
not
std
::
is_same
<
CompatibleObjectType
,
typename
BasicJsonType
::
object_t
>::
value
,
int
>
=
0
>
static
void
construct
(
BasicJsonType
&
j
,
const
CompatibleObjectType
&
obj
)
{
using
std
::
begin
;
using
std
::
end
;
j
.
m_type
=
value_t
::
object
;
j
.
m_value
.
object
=
j
.
template
create
<
typename
BasicJsonType
::
object_t
>
(
begin
(
obj
),
end
(
obj
));
j
.
assert_invariant
();
}
};
/////////////
// to_json //
/////////////
template
<
typename
BasicJsonType
,
typename
T
,
enable_if_t
<
std
::
is_same
<
T
,
typename
BasicJsonType
::
boolean_t
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
T
b
)
noexcept
{
external_constructor
<
value_t
::
boolean
>::
construct
(
j
,
b
);
}
template
<
typename
BasicJsonType
,
typename
CompatibleString
,
enable_if_t
<
std
::
is_constructible
<
typename
BasicJsonType
::
string_t
,
CompatibleString
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
const
CompatibleString
&
s
)
{
external_constructor
<
value_t
::
string
>::
construct
(
j
,
s
);
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
string_t
&&
s
)
{
external_constructor
<
value_t
::
string
>::
construct
(
j
,
std
::
move
(
s
));
}
template
<
typename
BasicJsonType
,
typename
FloatType
,
enable_if_t
<
std
::
is_floating_point
<
FloatType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
FloatType
val
)
noexcept
{
external_constructor
<
value_t
::
number_float
>::
construct
(
j
,
static_cast
<
typename
BasicJsonType
::
number_float_t
>
(
val
));
}
template
<
typename
BasicJsonType
,
typename
CompatibleNumberUnsignedType
,
enable_if_t
<
is_compatible_integer_type
<
typename
BasicJsonType
::
number_unsigned_t
,
CompatibleNumberUnsignedType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
CompatibleNumberUnsignedType
val
)
noexcept
{
external_constructor
<
value_t
::
number_unsigned
>::
construct
(
j
,
static_cast
<
typename
BasicJsonType
::
number_unsigned_t
>
(
val
));
}
template
<
typename
BasicJsonType
,
typename
CompatibleNumberIntegerType
,
enable_if_t
<
is_compatible_integer_type
<
typename
BasicJsonType
::
number_integer_t
,
CompatibleNumberIntegerType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
CompatibleNumberIntegerType
val
)
noexcept
{
external_constructor
<
value_t
::
number_integer
>::
construct
(
j
,
static_cast
<
typename
BasicJsonType
::
number_integer_t
>
(
val
));
}
template
<
typename
BasicJsonType
,
typename
EnumType
,
enable_if_t
<
std
::
is_enum
<
EnumType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
EnumType
e
)
noexcept
{
using
underlying_type
=
typename
std
::
underlying_type
<
EnumType
>::
type
;
external_constructor
<
value_t
::
number_integer
>::
construct
(
j
,
static_cast
<
underlying_type
>
(
e
));
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
const
std
::
vector
<
bool
>&
e
)
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
e
);
}
template
<
typename
BasicJsonType
,
typename
CompatibleArrayType
,
enable_if_t
<
is_compatible_array_type
<
BasicJsonType
,
CompatibleArrayType
>::
value
or
std
::
is_same
<
typename
BasicJsonType
::
array_t
,
CompatibleArrayType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
const
CompatibleArrayType
&
arr
)
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
arr
);
}
template
<
typename
BasicJsonType
,
typename
T
,
enable_if_t
<
std
::
is_convertible
<
T
,
BasicJsonType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
std
::
valarray
<
T
>
arr
)
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
std
::
move
(
arr
));
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
array_t
&&
arr
)
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
std
::
move
(
arr
));
}
template
<
typename
BasicJsonType
,
typename
CompatibleObjectType
,
enable_if_t
<
is_compatible_object_type
<
BasicJsonType
,
CompatibleObjectType
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
const
CompatibleObjectType
&
obj
)
{
external_constructor
<
value_t
::
object
>::
construct
(
j
,
obj
);
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
typename
BasicJsonType
::
object_t
&&
obj
)
{
external_constructor
<
value_t
::
object
>::
construct
(
j
,
std
::
move
(
obj
));
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
,
enable_if_t
<
not
std
::
is_constructible
<
typename
BasicJsonType
::
string_t
,
T
(
&
)[
N
]
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
T
(
&
arr
)[
N
])
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
arr
);
}
template
<
typename
BasicJsonType
,
typename
...
Args
>
void
to_json
(
BasicJsonType
&
j
,
const
std
::
pair
<
Args
...
>&
p
)
{
j
=
{
p
.
first
,
p
.
second
};
}
template
<
typename
BasicJsonType
,
typename
Tuple
,
std
::
size_t
...
Idx
>
void
to_json_tuple_impl
(
BasicJsonType
&
j
,
const
Tuple
&
t
,
index_sequence
<
Idx
...
>
)
{
j
=
{
std
::
get
<
Idx
>
(
t
)...};
}
template
<
typename
BasicJsonType
,
typename
...
Args
>
void
to_json
(
BasicJsonType
&
j
,
const
std
::
tuple
<
Args
...
>&
t
)
{
to_json_tuple_impl
(
j
,
t
,
index_sequence_for
<
Args
...
>
{});
}
struct
to_json_fn
{
private
:
template
<
typename
BasicJsonType
,
typename
T
>
auto
call
(
BasicJsonType
&
j
,
T
&&
val
,
priority_tag
<
1
>
/*unused*/
)
const
noexcept
(
noexcept
(
to_json
(
j
,
std
::
forward
<
T
>
(
val
))))
->
decltype
(
to_json
(
j
,
std
::
forward
<
T
>
(
val
)),
void
())
{
return
to_json
(
j
,
std
::
forward
<
T
>
(
val
));
}
template
<
typename
BasicJsonType
,
typename
T
>
void
call
(
BasicJsonType
&
/*unused*/
,
T
&&
/*unused*/
,
priority_tag
<
0
>
/*unused*/
)
const
noexcept
{
static_assert
(
sizeof
(
BasicJsonType
)
==
0
,
"could not find to_json() method in T's namespace"
);
#ifdef _MSC_VER
// MSVC does not show a stacktrace for the above assert
using
decayed
=
uncvref_t
<
T
>
;
static_assert
(
sizeof
(
typename
decayed
::
force_msvc_stacktrace
)
==
0
,
"forcing MSVC stacktrace to show which T we're talking about."
);
#endif
}
public
:
template
<
typename
BasicJsonType
,
typename
T
>
void
operator
()(
BasicJsonType
&
j
,
T
&&
val
)
const
noexcept
(
noexcept
(
std
::
declval
<
to_json_fn
>
().
call
(
j
,
std
::
forward
<
T
>
(
val
),
priority_tag
<
1
>
{})))
{
return
call
(
j
,
std
::
forward
<
T
>
(
val
),
priority_tag
<
1
>
{});
}
};
////////////////////
////////////////////
// input adapters //
// input adapters //
////////////////////
////////////////////
...
@@ -5884,12 +5570,6 @@ class json_ref
...
@@ -5884,12 +5570,6 @@ class json_ref
}
// namespace detail
}
// namespace detail
/// namespace to hold default `to_json` function
namespace
{
constexpr
const
auto
&
to_json
=
detail
::
static_const
<
detail
::
to_json_fn
>::
value
;
}
template
<
typename
,
typename
>
template
<
typename
,
typename
>
struct
adl_serializer
struct
adl_serializer
{
{
...
...
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