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
d0d80704
Commit
d0d80704
authored
Jan 12, 2017
by
Théo DELRIEU
Committed by
Théo DELRIEU
Jan 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add static_asserts
remove some useless trailing return types and && to help MSVC
parent
e678c075
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
5 deletions
+58
-5
src/json.hpp
src/json.hpp
+58
-5
No files found.
src/json.hpp
View file @
d0d80704
...
@@ -715,27 +715,81 @@ void from_json(Json const &j, ArithmeticType &val)
...
@@ -715,27 +715,81 @@ void from_json(Json const &j, ArithmeticType &val)
throw
std
::
domain_error
(
"type must be number, but is "
+
type_name
(
j
));
throw
std
::
domain_error
(
"type must be number, but is "
+
type_name
(
j
));
}
}
template
<
typename
Json
,
typename
T
>
constexpr
auto
has_adl_from_json
(
int
)
->
decltype
(
from_json
(
std
::
declval
<
Json
const
&>
(),
std
::
declval
<
T
&>
()),
true
)
{
return
true
;
}
template
<
typename
,
typename
>
constexpr
bool
has_adl_from_json
(
long
)
{
return
false
;
}
template
<
typename
Json
,
typename
T
>
constexpr
auto
has_adl_to_json
(
int
)
->
decltype
(
to_json
(
std
::
declval
<
Json
&>
(),
std
::
declval
<
T
const
&>
()),
true
)
{
return
true
;
}
template
<
typename
,
typename
>
constexpr
bool
has_adl_to_json
(
long
)
{
return
false
;
}
struct
to_json_fn
struct
to_json_fn
{
{
template
<
typename
Json
,
typename
T
>
private:
constexpr
auto
operator
()(
Json
&&
j
,
T
&&
val
)
const
template
<
typename
Json
,
typename
T
,
enable_if_t
<
has_adl_to_json
<
Json
,
T
>(
0
),
int
>
=
0
>
auto
operator
()(
Json
&&
j
,
T
&&
val
)
const
noexcept
(
noexcept
(
to_json
(
std
::
forward
<
Json
>
(
j
),
std
::
forward
<
T
>
(
val
))))
noexcept
(
noexcept
(
to_json
(
std
::
forward
<
Json
>
(
j
),
std
::
forward
<
T
>
(
val
))))
->
decltype
(
to_json
(
std
::
forward
<
Json
>
(
j
),
std
::
forward
<
T
>
(
val
)),
->
decltype
(
to_json
(
std
::
forward
<
Json
>
(
j
),
std
::
forward
<
T
>
(
val
)),
void
())
void
())
{
{
return
to_json
(
std
::
forward
<
Json
>
(
j
),
std
::
forward
<
T
>
(
val
));
return
to_json
(
std
::
forward
<
Json
>
(
j
),
std
::
forward
<
T
>
(
val
));
}
}
template
<
typename
Json
,
typename
T
,
enable_if_t
<
not
has_adl_to_json
<
Json
,
T
>(
0
),
int
>
=
0
>
void
operator
()(
Json
&&
,
T
&&
)
const
noexcept
{
static_assert
(
has_adl_to_json
<
Json
,
T
>
(
0
),
"to_json method in T's namespace can not be called"
);
}
public:
template
<
typename
Json
,
typename
T
>
void
operator
()(
Json
&
j
,
T
&&
val
)
const
noexcept
(
noexcept
(
std
::
declval
<
to_json_fn
>
().
call
(
0
,
j
,
std
::
forward
<
T
>
(
val
))))
{
return
call
(
0
,
j
,
std
::
forward
<
T
>
(
val
));
}
};
};
struct
from_json_fn
struct
from_json_fn
{
{
template
<
typename
Json
,
typename
T
>
private:
constexpr
auto
operator
()(
Json
&&
j
,
T
&
val
)
const
template
<
typename
Json
,
typename
T
,
enable_if_t
<
has_adl_from_json
<
Json
,
T
>(
0
),
int
>
=
0
>
auto
operator
()(
Json
&&
j
,
T
&
val
)
const
noexcept
(
noexcept
(
from_json
(
std
::
forward
<
Json
>
(
j
),
val
)))
noexcept
(
noexcept
(
from_json
(
std
::
forward
<
Json
>
(
j
),
val
)))
->
decltype
(
from_json
(
std
::
forward
<
Json
>
(
j
),
val
),
void
())
->
decltype
(
from_json
(
std
::
forward
<
Json
>
(
j
),
val
),
void
())
{
{
return
from_json
(
std
::
forward
<
Json
>
(
j
),
val
);
return
from_json
(
std
::
forward
<
Json
>
(
j
),
val
);
}
}
template
<
typename
Json
,
typename
T
,
enable_if_t
<
not
has_adl_from_json
<
Json
,
T
>(
0
),
int
>
=
0
>
void
operator
()(
Json
&&
,
T
&
)
const
noexcept
{
static_assert
(
has_adl_from_json
<
Json
,
T
>
(
0
),
"from_json method in T's namespace can not be called"
);
}
public:
template
<
typename
Json
,
typename
T
>
void
operator
()(
Json
const
&
j
,
T
&
val
)
const
noexcept
(
noexcept
(
std
::
declval
<
from_json_fn
>
().
call
(
0
,
j
,
val
)))
{
return
call
(
0
,
j
,
val
);
}
};
};
/*!
/*!
...
@@ -757,7 +811,6 @@ struct DecimalSeparator : std::numpunct<char>
...
@@ -757,7 +811,6 @@ struct DecimalSeparator : std::numpunct<char>
return
'.'
;
return
'.'
;
}
}
};
};
}
}
// taken from ranges-v3
// taken from ranges-v3
...
...
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