diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index 902b9cd..4e3ff6a 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -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 std::enable_if< std::is_floating_point::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 std::enable_if::value, void>::type +inner_encode(const T& rhs, std::stringstream& stream){ + stream << rhs; +} +} + #define YAML_DEFINE_CONVERT_STREAMABLE(type, negative_op) \ template <> \ struct convert { \ + \ static Node encode(const type& rhs) { \ std::stringstream stream; \ stream.precision(std::numeric_limits::max_digits10); \ - if (std::is_floating_point::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()); \ } \ \