Patched for gcc version <= 3.3 (just fall back to original version of Node::Read)

This commit is contained in:
Jesse Beder
2009-09-16 04:01:40 +00:00
parent 98bebfb628
commit 5733b77b84
2 changed files with 16 additions and 4 deletions

View File

@@ -79,22 +79,22 @@ namespace YAML
template <typename T> template <typename T>
inline bool operator == (const T& value, const Node& node) { inline bool operator == (const T& value, const Node& node) {
return value == node.Read<T>(); return value == node.operator T();
} }
template <typename T> template <typename T>
inline bool operator == (const Node& node, const T& value) { inline bool operator == (const Node& node, const T& value) {
return value == node.Read<T>(); return value == node.operator T();
} }
template <typename T> template <typename T>
inline bool operator != (const T& value, const Node& node) { inline bool operator != (const T& value, const Node& node) {
return value != node.Read<T>(); return value != node.operator T();
} }
template <typename T> template <typename T>
inline bool operator != (const Node& node, const T& value) { inline bool operator != (const Node& node, const T& value) {
return value != node.Read<T>(); return value != node.operator T();
} }
inline bool operator == (const char *value, const Node& node) { inline bool operator == (const char *value, const Node& node) {

View File

@@ -6,7 +6,18 @@ namespace YAML
// (the goal is to call ConvertScalar if we can, and fall back to operator >> if not) // (the goal is to call ConvertScalar if we can, and fall back to operator >> if not)
// thanks to litb from stackoverflow.com // thanks to litb from stackoverflow.com
// http://stackoverflow.com/questions/1386183/how-to-call-a-templated-function-if-it-exists-and-something-else-otherwise/1386390#1386390 // http://stackoverflow.com/questions/1386183/how-to-call-a-templated-function-if-it-exists-and-something-else-otherwise/1386390#1386390
// Note: this doesn't work on gcc 3.2, but does on gcc 3.4 and above. I'm not sure about 3.3.
#if (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ <= 3))
// trick doesn't work? Just fall back to ConvertScalar.
// This means that we can't use any user-defined types as keys in a map
template <typename T>
inline bool Node::Read(T& value) const {
return ConvertScalar(*this, value);
}
#else
// usual case: the trick!
template<bool> template<bool>
struct read_impl; struct read_impl;
@@ -52,6 +63,7 @@ namespace YAML
return read_impl<sizeof (fallback::flag(), Convert(std::string(), value), fallback::flag()) != 1>::read(*this, value); return read_impl<sizeof (fallback::flag(), Convert(std::string(), value), fallback::flag()) != 1>::read(*this, value);
} }
#endif // done with trick
// the main conversion function // the main conversion function
template <typename T> template <typename T>