mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Split conversion call that uses std::signbit with unsupported parameters with enable_if (#824)
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
#include "yaml-cpp/node/type.h"
|
#include "yaml-cpp/node/type.h"
|
||||||
#include "yaml-cpp/null.h"
|
#include "yaml-cpp/null.h"
|
||||||
|
|
||||||
|
|
||||||
namespace YAML {
|
namespace YAML {
|
||||||
class Binary;
|
class Binary;
|
||||||
struct _Null;
|
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) \
|
#define YAML_DEFINE_CONVERT_STREAMABLE(type, negative_op) \
|
||||||
template <> \
|
template <> \
|
||||||
struct convert<type> { \
|
struct convert<type> { \
|
||||||
|
\
|
||||||
static Node encode(const type& rhs) { \
|
static Node encode(const type& rhs) { \
|
||||||
std::stringstream stream; \
|
std::stringstream stream; \
|
||||||
stream.precision(std::numeric_limits<type>::max_digits10); \
|
stream.precision(std::numeric_limits<type>::max_digits10); \
|
||||||
if (std::is_floating_point<type>::value) { \
|
conversion::inner_encode(rhs, stream); \
|
||||||
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; \
|
|
||||||
} \
|
|
||||||
return Node(stream.str()); \
|
return Node(stream.str()); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
Reference in New Issue
Block a user