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
ff0b18d1
Unverified
Commit
ff0b18d1
authored
Mar 11, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/vector_bool' into develop
parents
c7afb34e
d9e2dd03
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
0 deletions
+47
-0
json.hpp
src/json.hpp
+19
-0
json.hpp.re2c
src/json.hpp.re2c
+19
-0
unit-regression.cpp
test/src/unit-regression.cpp
+9
-0
No files found.
src/json.hpp
View file @
ff0b18d1
...
@@ -324,6 +324,19 @@ struct external_constructor<value_t::array>
...
@@ -324,6 +324,19 @@ struct external_constructor<value_t::array>
j
.
m_value
.
array
=
j
.
template
create
<
typename
BasicJsonType
::
array_t
>
(
begin
(
arr
),
end
(
arr
));
j
.
m_value
.
array
=
j
.
template
create
<
typename
BasicJsonType
::
array_t
>
(
begin
(
arr
),
end
(
arr
));
j
.
assert_invariant
();
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
(
bool
x
:
arr
)
{
j
.
m_value
.
array
->
push_back
(
x
);
}
j
.
assert_invariant
();
}
};
};
template
<>
template
<>
...
@@ -562,6 +575,12 @@ void to_json(BasicJsonType& j, UnscopedEnumType e) noexcept
...
@@ -562,6 +575,12 @@ void to_json(BasicJsonType& j, UnscopedEnumType e) noexcept
external_constructor
<
value_t
::
number_integer
>::
construct
(
j
,
e
);
external_constructor
<
value_t
::
number_integer
>::
construct
(
j
,
e
);
}
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
const
std
::
vector
<
bool
>&
e
)
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
e
);
}
template
<
template
<
typename
BasicJsonType
,
typename
CompatibleArrayType
,
typename
BasicJsonType
,
typename
CompatibleArrayType
,
enable_if_t
<
enable_if_t
<
...
...
src/json.hpp.re2c
View file @
ff0b18d1
...
@@ -324,6 +324,19 @@ struct external_constructor<value_t::array>
...
@@ -324,6 +324,19 @@ struct external_constructor<value_t::array>
j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
j.assert_invariant();
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 (bool x : arr)
{
j.m_value.array->push_back(x);
}
j.assert_invariant();
}
};
};
template<>
template<>
...
@@ -562,6 +575,12 @@ void to_json(BasicJsonType& j, UnscopedEnumType e) noexcept
...
@@ -562,6 +575,12 @@ void to_json(BasicJsonType& j, UnscopedEnumType e) noexcept
external_constructor<value_t::number_integer>::construct(j, e);
external_constructor<value_t::number_integer>::construct(j, e);
}
}
template<typename BasicJsonType>
void to_json(BasicJsonType& j, const std::vector<bool>& e)
{
external_constructor<value_t::array>::construct(j, e);
}
template <
template <
typename BasicJsonType, typename CompatibleArrayType,
typename BasicJsonType, typename CompatibleArrayType,
enable_if_t <
enable_if_t <
...
...
test/src/unit-regression.cpp
View file @
ff0b18d1
...
@@ -795,4 +795,13 @@ TEST_CASE("regression tests")
...
@@ -795,4 +795,13 @@ TEST_CASE("regression tests")
std
::
string
s2
=
j2
.
dump
();
std
::
string
s2
=
j2
.
dump
();
CHECK
(
s1
==
s2
);
CHECK
(
s1
==
s2
);
}
}
SECTION
(
"issue #494 - conversion from vector<bool> to json fails to build"
)
{
std
::
vector
<
bool
>
boolVector
=
{
false
,
true
,
false
,
false
};
json
j
;
j
[
"bool_vector"
]
=
boolVector
;
CHECK
(
j
[
"bool_vector"
].
dump
()
==
"[false,true,false,false]"
);
}
}
}
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