Commit d78d1653 authored by Jesse Beder's avatar Jesse Beder
Browse files

Set the default operator >> to not compile unless there is a scalar...

Set the default operator >> to not compile unless there is a scalar conversion, so it doesn't interfere with user-defined types
parent 62634f53
......@@ -14,6 +14,17 @@
namespace YAML
{
// traits for conversion
template<typename T>
struct is_scalar_convertible { enum { value = is_numeric<T>::value }; };
template<> struct is_scalar_convertible<std::string> { enum { value = true }; };
template<> struct is_scalar_convertible<bool> { enum { value = true }; };
template<> struct is_scalar_convertible<_Null> { enum { value = true }; };
// actual conversion
inline bool Convert(const std::string& input, std::string& output) {
output = input;
return true;
......
......@@ -66,7 +66,7 @@ namespace YAML
const T to() const;
template <typename T>
friend YAML_CPP_API void operator >> (const Node& node, T& value);
friend YAML_CPP_API typename enable_if<is_scalar_convertible<T> >::type operator >> (const Node& node, T& value);
// retrieval for maps and sequences
template <typename T>
......
......@@ -20,7 +20,7 @@ namespace YAML
}
template <typename T>
inline void operator >> (const Node& node, T& value) {
inline typename enable_if<is_scalar_convertible<T> >::type operator >> (const Node& node, T& value) {
if(!ConvertScalar(node, value))
throw InvalidScalar(node.m_mark);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment