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
98b21524
Unverified
Commit
98b21524
authored
Dec 29, 2020
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' of
https://github.com/nlohmann/json
into std_bytes
parents
5dd06714
ff3863dc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
13 deletions
+80
-13
include/nlohmann/detail/input/input_adapters.hpp
include/nlohmann/detail/input/input_adapters.hpp
+26
-5
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+28
-7
test/src/unit-user_defined_input.cpp
test/src/unit-user_defined_input.cpp
+26
-1
No files found.
include/nlohmann/detail/input/input_adapters.hpp
View file @
98b21524
...
@@ -371,14 +371,35 @@ typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapte
...
@@ -371,14 +371,35 @@ typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapte
}
}
// Convenience shorthand from container to iterator
// Convenience shorthand from container to iterator
// Enables ADL on begin(container) and end(container)
// Encloses the using declarations in namespace for not to leak them to outside scope
namespace
container_input_adapter_factory_impl
{
using
std
::
begin
;
using
std
::
end
;
template
<
typename
ContainerType
,
typename
Enable
=
void
>
struct
container_input_adapter_factory
{};
template
<
typename
ContainerType
>
template
<
typename
ContainerType
>
auto
input_adapter
(
const
ContainerType
&
container
)
->
decltype
(
input_adapter
(
begin
(
container
),
end
(
container
)))
struct
container_input_adapter_factory
<
ContainerType
,
void_t
<
decltype
(
begin
(
std
::
declval
<
ContainerType
>
()),
end
(
std
::
declval
<
ContainerType
>
()))
>
>
{
{
// Enable ADL
using
adapter_type
=
decltype
(
input_adapter
(
begin
(
std
::
declval
<
ContainerType
>
()),
end
(
std
::
declval
<
ContainerType
>
())));
using
std
::
begin
;
using
std
::
end
;
static
adapter_type
create
(
const
ContainerType
&
container
)
{
return
input_adapter
(
begin
(
container
),
end
(
container
));
}
};
}
return
input_adapter
(
begin
(
container
),
end
(
container
));
template
<
typename
ContainerType
>
typename
container_input_adapter_factory_impl
::
container_input_adapter_factory
<
ContainerType
>::
adapter_type
input_adapter
(
const
ContainerType
&
container
)
{
return
container_input_adapter_factory_impl
::
container_input_adapter_factory
<
ContainerType
>::
create
(
container
);
}
}
// Special cases with fast paths
// Special cases with fast paths
...
...
single_include/nlohmann/json.hpp
View file @
98b21524
...
@@ -5183,14 +5183,35 @@ typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapte
...
@@ -5183,14 +5183,35 @@ typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapte
}
}
// Convenience shorthand from container to iterator
// Convenience shorthand from container to iterator
// Enables ADL on begin(container) and end(container)
// Encloses the using declarations in namespace for not to leak them to outside scope
namespace
container_input_adapter_factory_impl
{
using
std
::
begin
;
using
std
::
end
;
template
<
typename
ContainerType
,
typename
Enable
=
void
>
struct
container_input_adapter_factory
{};
template
<
typename
ContainerType
>
template
<
typename
ContainerType
>
auto
input_adapter
(
const
ContainerType
&
container
)
->
decltype
(
input_adapter
(
begin
(
container
),
end
(
container
)))
struct
container_input_adapter_factory
<
ContainerType
,
void_t
<
decltype
(
begin
(
std
::
declval
<
ContainerType
>
()),
end
(
std
::
declval
<
ContainerType
>
()))
>
>
{
{
// Enable ADL
using
adapter_type
=
decltype
(
input_adapter
(
begin
(
std
::
declval
<
ContainerType
>
()),
end
(
std
::
declval
<
ContainerType
>
())));
using
std
::
begin
;
using
std
::
end
;
static
adapter_type
create
(
const
ContainerType
&
container
)
{
return
input_adapter
(
begin
(
container
),
end
(
container
));
}
};
return
input_adapter
(
begin
(
container
),
end
(
container
));
}
template
<
typename
ContainerType
>
typename
container_input_adapter_factory_impl
::
container_input_adapter_factory
<
ContainerType
>::
adapter_type
input_adapter
(
const
ContainerType
&
container
)
{
return
container_input_adapter_factory_impl
::
container_input_adapter_factory
<
ContainerType
>::
create
(
container
);
}
}
// Special cases with fast paths
// Special cases with fast paths
...
@@ -16801,7 +16822,7 @@ class basic_json
...
@@ -16801,7 +16822,7 @@ class basic_json
detail
::
parser_callback_t
<
basic_json
>
cb
=
nullptr
,
detail
::
parser_callback_t
<
basic_json
>
cb
=
nullptr
,
const
bool
allow_exceptions
=
true
,
const
bool
allow_exceptions
=
true
,
const
bool
ignore_comments
=
false
const
bool
ignore_comments
=
false
)
)
{
{
return
::
nlohmann
::
detail
::
parser
<
basic_json
,
InputAdapterType
>
(
std
::
move
(
adapter
),
return
::
nlohmann
::
detail
::
parser
<
basic_json
,
InputAdapterType
>
(
std
::
move
(
adapter
),
std
::
move
(
cb
),
allow_exceptions
,
ignore_comments
);
std
::
move
(
cb
),
allow_exceptions
,
ignore_comments
);
...
@@ -25346,7 +25367,7 @@ template<>
...
@@ -25346,7 +25367,7 @@ template<>
inline
void
swap
<
nlohmann
::
json
>
(
nlohmann
::
json
&
j1
,
nlohmann
::
json
&
j2
)
noexcept
(
inline
void
swap
<
nlohmann
::
json
>
(
nlohmann
::
json
&
j1
,
nlohmann
::
json
&
j2
)
noexcept
(
is_nothrow_move_constructible
<
nlohmann
::
json
>::
value
&&
is_nothrow_move_constructible
<
nlohmann
::
json
>::
value
&&
is_nothrow_move_assignable
<
nlohmann
::
json
>::
value
is_nothrow_move_assignable
<
nlohmann
::
json
>::
value
)
)
{
{
j1
.
swap
(
j2
);
j1
.
swap
(
j2
);
}
}
...
...
test/src/unit-user_defined_input.cpp
View file @
98b21524
...
@@ -63,7 +63,7 @@ const char* end(const MyContainer& c)
...
@@ -63,7 +63,7 @@ const char* end(const MyContainer& c)
return
c
.
data
+
strlen
(
c
.
data
);
return
c
.
data
+
strlen
(
c
.
data
);
}
}
TEST_CASE
(
"Custom container"
)
TEST_CASE
(
"Custom container
non-member begin/end
"
)
{
{
MyContainer
data
{
"[1,2,3,4]"
};
MyContainer
data
{
"[1,2,3,4]"
};
...
@@ -75,6 +75,31 @@ TEST_CASE("Custom container")
...
@@ -75,6 +75,31 @@ TEST_CASE("Custom container")
}
}
TEST_CASE
(
"Custom container member begin/end"
)
{
struct
MyContainer2
{
const
char
*
data
;
const
char
*
begin
()
const
{
return
data
;
}
const
char
*
end
()
const
{
return
data
+
strlen
(
data
);
}
};
MyContainer2
data
{
"[1,2,3,4]"
};
json
as_json
=
json
::
parse
(
data
);
CHECK
(
as_json
.
at
(
0
)
==
1
);
CHECK
(
as_json
.
at
(
1
)
==
2
);
CHECK
(
as_json
.
at
(
2
)
==
3
);
CHECK
(
as_json
.
at
(
3
)
==
4
);
}
TEST_CASE
(
"Custom iterator"
)
TEST_CASE
(
"Custom iterator"
)
{
{
const
char
*
raw_data
=
"[1,2,3,4]"
;
const
char
*
raw_data
=
"[1,2,3,4]"
;
...
...
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