Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
89a84919
Commit
89a84919
authored
Apr 25, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor changes
parent
fc58a735
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
18 deletions
+20
-18
src/json.hpp
src/json.hpp
+10
-9
src/json.hpp.re2c
src/json.hpp.re2c
+10
-9
No files found.
src/json.hpp
View file @
89a84919
...
...
@@ -504,14 +504,15 @@ class basic_json
{}
/// create a container (array or object) from an initializer list
inline
basic_json
(
list_init_t
l
,
bool
type_deduction
=
true
,
value_t
manual_type
=
value_t
::
array
)
inline
basic_json
(
list_init_t
init
,
bool
type_deduction
=
true
,
value_t
manual_type
=
value_t
::
array
)
{
// the initializer list could describe an object
bool
is_object
=
true
;
// check if each element is an array with two elements whose first element
// is a string
for
(
const
auto
&
element
:
l
)
for
(
const
auto
&
element
:
init
)
{
if
((
element
.
m_final
and
element
.
m_type
==
value_t
::
array
)
or
(
element
.
m_type
!=
value_t
::
array
or
element
.
size
()
!=
2
...
...
@@ -551,7 +552,7 @@ class basic_json
m_value
.
object
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
object
);
for
(
auto
&
element
:
l
)
for
(
auto
&
element
:
init
)
{
m_value
.
object
->
emplace
(
std
::
move
(
*
(
element
[
0
].
m_value
.
string
)),
std
::
move
(
element
[
1
]));
}
...
...
@@ -562,20 +563,20 @@ class basic_json
m_type
=
value_t
::
array
;
AllocatorType
<
array_t
>
alloc
;
m_value
.
array
=
alloc
.
allocate
(
1
);
alloc
.
construct
(
m_value
.
array
,
std
::
move
(
l
));
alloc
.
construct
(
m_value
.
array
,
std
::
move
(
init
));
}
}
/// explicitly create an array from an initializer list
inline
static
basic_json
array
(
list_init_t
l
=
list_init_t
())
inline
static
basic_json
array
(
list_init_t
init
=
list_init_t
())
{
return
basic_json
(
l
,
false
,
value_t
::
array
);
return
basic_json
(
init
,
false
,
value_t
::
array
);
}
/// explicitly create an object from an initializer list
inline
static
basic_json
object
(
list_init_t
l
=
list_init_t
())
inline
static
basic_json
object
(
list_init_t
init
=
list_init_t
())
{
return
basic_json
(
l
,
false
,
value_t
::
object
);
return
basic_json
(
init
,
false
,
value_t
::
object
);
}
/// construct an array with count copies of given value
...
...
@@ -764,6 +765,7 @@ class basic_json
std
::
is_nothrow_move_assignable
<
json_value
>::
value
)
{
using
std
::
swap
;
std
::
swap
(
m_type
,
other
.
m_type
);
std
::
swap
(
m_value
,
other
.
m_value
);
return
*
this
;
...
...
@@ -3374,7 +3376,6 @@ class basic_json
case
(
basic_json
:
:
value_t
::
object
)
:
{
throw
std
::
domain_error
(
"cannot use operator+= for object iterators"
);
break
;
}
case
(
basic_json
:
:
value_t
::
array
)
:
...
...
src/json.hpp.re2c
View file @
89a84919
...
...
@@ -504,14 +504,15 @@ class basic_json
{}
/// create a container (array or object) from an initializer list
inline basic_json(list_init_t l, bool type_deduction = true, value_t manual_type = value_t::array)
inline basic_json(list_init_t init, bool type_deduction = true,
value_t manual_type = value_t::array)
{
// the initializer list could describe an object
bool is_object = true;
// check if each element is an array with two elements whose first element
// is a string
for (const auto& element :
l
)
for (const auto& element :
init
)
{
if ((element.m_final and element.m_type == value_t::array)
or (element.m_type != value_t::array or element.size() != 2
...
...
@@ -551,7 +552,7 @@ class basic_json
m_value.object = alloc.allocate(1);
alloc.construct(m_value.object);
for (auto& element :
l
)
for (auto& element :
init
)
{
m_value.object->emplace(std::move(*(element[0].m_value.string)), std::move(element[1]));
}
...
...
@@ -562,20 +563,20 @@ class basic_json
m_type = value_t::array;
AllocatorType<array_t> alloc;
m_value.array = alloc.allocate(1);
alloc.construct(m_value.array, std::move(
l
));
alloc.construct(m_value.array, std::move(
init
));
}
}
/// explicitly create an array from an initializer list
inline static basic_json array(list_init_t
l
= list_init_t())
inline static basic_json array(list_init_t
init
= list_init_t())
{
return basic_json(
l
, false, value_t::array);
return basic_json(
init
, false, value_t::array);
}
/// explicitly create an object from an initializer list
inline static basic_json object(list_init_t
l
= list_init_t())
inline static basic_json object(list_init_t
init
= list_init_t())
{
return basic_json(
l
, false, value_t::object);
return basic_json(
init
, false, value_t::object);
}
/// construct an array with count copies of given value
...
...
@@ -764,6 +765,7 @@ class basic_json
std::is_nothrow_move_assignable<json_value>::value
)
{
using std::swap;
std::swap(m_type, other.m_type);
std::swap(m_value, other.m_value);
return *this;
...
...
@@ -3374,7 +3376,6 @@ class basic_json
case (basic_json::value_t::object):
{
throw std::domain_error("cannot use operator+= for object iterators");
break;
}
case (basic_json::value_t::array):
...
...
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