Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
畅游知识海洋
json
提交
08d78105
J
json
项目概览
畅游知识海洋
/
json
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
json
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
08d78105
编写于
6月 19, 2017
作者:
T
Théo DELRIEU
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add from_json support for std::array
上级
6e4910d5
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
16 addition
and
3 deletion
+16
-3
src/json.hpp
src/json.hpp
+10
-1
test/src/unit-constructor1.cpp
test/src/unit-constructor1.cpp
+6
-2
未找到文件。
src/json.hpp
浏览文件 @
08d78105
...
@@ -1063,6 +1063,15 @@ auto from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, prio
...
@@ -1063,6 +1063,15 @@ auto from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, prio
});
});
}
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
>
void
from_json_array_impl
(
const
BasicJsonType
&
j
,
std
::
array
<
T
,
N
>&
arr
,
priority_tag
<
2
>
)
{
for
(
std
::
size_t
i
=
0
;
i
<
N
;
++
i
)
{
arr
[
i
]
=
j
.
at
(
i
).
template
get
<
T
>();
}
}
template
<
typename
BasicJsonType
,
typename
CompatibleArrayType
,
template
<
typename
BasicJsonType
,
typename
CompatibleArrayType
,
enable_if_t
<
is_compatible_array_type
<
BasicJsonType
,
CompatibleArrayType
>
::
value
and
enable_if_t
<
is_compatible_array_type
<
BasicJsonType
,
CompatibleArrayType
>
::
value
and
std
::
is_convertible
<
BasicJsonType
,
typename
CompatibleArrayType
::
value_type
>::
value
and
std
::
is_convertible
<
BasicJsonType
,
typename
CompatibleArrayType
::
value_type
>::
value
and
...
@@ -1074,7 +1083,7 @@ void from_json(const BasicJsonType& j, CompatibleArrayType& arr)
...
@@ -1074,7 +1083,7 @@ void from_json(const BasicJsonType& j, CompatibleArrayType& arr)
JSON_THROW
(
type_error
::
create
(
302
,
"type must be array, but is "
+
j
.
type_name
()));
JSON_THROW
(
type_error
::
create
(
302
,
"type must be array, but is "
+
j
.
type_name
()));
}
}
from_json_array_impl
(
j
,
arr
,
priority_tag
<
1
>
{});
from_json_array_impl
(
j
,
arr
,
priority_tag
<
2
>
{});
}
}
template
<
typename
BasicJsonType
,
typename
CompatibleObjectType
,
template
<
typename
BasicJsonType
,
typename
CompatibleObjectType
,
...
...
test/src/unit-constructor1.cpp
浏览文件 @
08d78105
...
@@ -283,12 +283,13 @@ TEST_CASE("constructors")
...
@@ -283,12 +283,13 @@ TEST_CASE("constructors")
CHECK
(
std
::
get
<
2
>
(
t
)
==
j
[
2
]);
CHECK
(
std
::
get
<
2
>
(
t
)
==
j
[
2
]);
}
}
SECTION
(
"std::pair/tuple failures"
)
SECTION
(
"std::pair/tuple
/array
failures"
)
{
{
json
j
{
1
};
json
j
{
1
};
CHECK_THROWS
((
j
.
get
<
std
::
pair
<
int
,
int
>>
()));
CHECK_THROWS
((
j
.
get
<
std
::
pair
<
int
,
int
>>
()));
CHECK_THROWS
((
j
.
get
<
std
::
tuple
<
int
,
int
>>
()));
CHECK_THROWS
((
j
.
get
<
std
::
tuple
<
int
,
int
>>
()));
CHECK_THROWS
((
j
.
get
<
std
::
array
<
int
,
3
>>
()));
}
}
SECTION
(
"std::forward_list<json>"
)
SECTION
(
"std::forward_list<json>"
)
...
@@ -299,12 +300,15 @@ TEST_CASE("constructors")
...
@@ -299,12 +300,15 @@ TEST_CASE("constructors")
CHECK
(
j
==
j_reference
);
CHECK
(
j
==
j_reference
);
}
}
SECTION
(
"std::array<json,
5
>"
)
SECTION
(
"std::array<json,
6
>"
)
{
{
std
::
array
<
json
,
6
>
a
{{
json
(
1
),
json
(
1u
),
json
(
2.2
),
json
(
false
),
json
(
"string"
),
json
()}};
std
::
array
<
json
,
6
>
a
{{
json
(
1
),
json
(
1u
),
json
(
2.2
),
json
(
false
),
json
(
"string"
),
json
()}};
json
j
(
a
);
json
j
(
a
);
CHECK
(
j
.
type
()
==
json
::
value_t
::
array
);
CHECK
(
j
.
type
()
==
json
::
value_t
::
array
);
CHECK
(
j
==
j_reference
);
CHECK
(
j
==
j_reference
);
const
auto
a2
=
j
.
get
<
std
::
array
<
json
,
6
>>
();
CHECK
(
a2
==
a
);
}
}
SECTION
(
"std::vector<json>"
)
SECTION
(
"std::vector<json>"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录