mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Set the default operator >> to not compile unless there is a scalar conversion, so it doesn't interfere with user-defined types
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user