mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Refactored the traits a bit, and added displaying the key to string and numeric key not found errors
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
|
||||
#include "null.h"
|
||||
#include "traits.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
@@ -18,34 +19,8 @@ namespace YAML
|
||||
bool Convert(const std::string& input, bool& output);
|
||||
bool Convert(const std::string& input, _Null& output);
|
||||
|
||||
template <typename>
|
||||
struct is_numeric { enum { value = false }; };
|
||||
|
||||
template <> struct is_numeric <char> { enum { value = true }; };
|
||||
template <> struct is_numeric <unsigned char> { enum { value = true }; };
|
||||
template <> struct is_numeric <int> { enum { value = true }; };
|
||||
template <> struct is_numeric <unsigned int> { enum { value = true }; };
|
||||
template <> struct is_numeric <long int> { enum { value = true }; };
|
||||
template <> struct is_numeric <unsigned long int> { enum { value = true }; };
|
||||
template <> struct is_numeric <short int> { enum { value = true }; };
|
||||
template <> struct is_numeric <unsigned short int> { enum { value = true }; };
|
||||
template <> struct is_numeric <long long> { enum { value = true }; };
|
||||
template <> struct is_numeric <unsigned long long> { enum { value = true }; };
|
||||
template <> struct is_numeric <float> { enum { value = true }; };
|
||||
template <> struct is_numeric <double> { enum { value = true }; };
|
||||
template <> struct is_numeric <long double> { enum { value = true }; };
|
||||
|
||||
|
||||
template <typename T, typename, bool = T::value>
|
||||
struct enable_if;
|
||||
|
||||
template <typename T, typename R>
|
||||
struct enable_if <T, R, true> {
|
||||
typedef R type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline bool Convert(const std::string& input, T& output, typename enable_if<is_numeric<T>, T>::type * = 0) {
|
||||
inline bool Convert(const std::string& input, T& output, typename enable_if<is_numeric<T> >::type * = 0) {
|
||||
std::stringstream stream(input);
|
||||
stream.unsetf(std::ios::dec);
|
||||
return stream >> output;
|
||||
|
Reference in New Issue
Block a user