Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
b2f89386
Unverified
Commit
b2f89386
authored
Mar 11, 2020
by
Dekken
Committed by
GitHub
Mar 11, 2020
Browse files
Split conversion call that uses std::signbit with unsupported parameters with enable_if (#824)
parent
1bfbd2be
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
15 deletions
+27
-15
include/yaml-cpp/node/convert.h
include/yaml-cpp/node/convert.h
+27
-15
No files found.
include/yaml-cpp/node/convert.h
View file @
b2f89386
...
...
@@ -23,6 +23,7 @@
#include "yaml-cpp/node/type.h"
#include "yaml-cpp/null.h"
namespace
YAML
{
class
Binary
;
struct
_Null
;
...
...
@@ -90,27 +91,38 @@ struct convert<_Null> {
}
};
namespace
conversion
{
template
<
typename
T
>
typename
std
::
enable_if
<
std
::
is_floating_point
<
T
>::
value
,
void
>::
type
inner_encode
(
const
T
&
rhs
,
std
::
stringstream
&
stream
){
if
(
std
::
isnan
(
rhs
))
{
stream
<<
".nan"
;
}
else
if
(
std
::
isinf
(
rhs
))
{
if
(
std
::
signbit
(
rhs
))
{
stream
<<
"-.inf"
;
}
else
{
stream
<<
".inf"
;
}
}
else
{
stream
<<
rhs
;
}
}
template
<
typename
T
>
typename
std
::
enable_if
<!
std
::
is_floating_point
<
T
>::
value
,
void
>::
type
inner_encode
(
const
T
&
rhs
,
std
::
stringstream
&
stream
){
stream
<<
rhs
;
}
}
#define YAML_DEFINE_CONVERT_STREAMABLE(type, negative_op) \
template <> \
struct convert<type> { \
\
static Node encode(const type& rhs) { \
std::stringstream stream; \
stream.precision(std::numeric_limits<type>::max_digits10); \
if (std::is_floating_point<type>::value) { \
if (std::isnan(rhs)) { \
stream << ".nan"; \
} else if (std::isinf(rhs)) { \
if (std::signbit(rhs)) { \
stream << "-.inf"; \
} else { \
stream << ".inf"; \
} \
} else { \
stream << rhs; \
} \
} else { \
stream << rhs; \
} \
conversion::inner_encode(rhs, stream); \
return Node(stream.str()); \
} \
\
...
...
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