8
8
namespace fly ::detail {
9
9
10
10
/* *
11
- * Helper struct to convert a std::basic_string type to a plain-old-data type, e.g. int or float.
11
+ * Helper struct to convert a std::string to a plain-old-data type, e.g. int or float.
12
12
*
13
13
* Ideally, this entire helper can be removed when the STL supports floating point types with
14
14
* std::from_chars. However, only integral types are currently supported. Thus, integral types will
@@ -19,14 +19,10 @@ namespace fly::detail {
19
19
* @author Timothy Flynn ([email protected] )
20
20
* @version March 21, 2019
21
21
*/
22
- template <typename StringType, typename T>
23
- struct BasicStringConverter ;
24
-
25
- // ==================================================================================================
26
- template <typename StringType, typename T>
27
- struct BasicStringConverter
22
+ template <typename T>
23
+ struct Converter
28
24
{
29
- static std::optional<T> convert (const StringType &value)
25
+ static std::optional<T> convert (const std::string &value)
30
26
{
31
27
const auto *begin = value.data ();
32
28
const auto *end = begin + value.size ();
@@ -44,15 +40,13 @@ struct BasicStringConverter
44
40
};
45
41
46
42
// ==================================================================================================
47
- template <typename StringType >
48
- struct BasicStringConverter <StringType, float >
43
+ template <>
44
+ struct Converter < float >
49
45
{
50
- using value_type = float ;
51
-
52
- static std::optional<value_type> convert (const StringType &value)
46
+ static std::optional<float > convert (const std::string &value)
53
47
{
54
48
std::size_t index = 0 ;
55
- value_type result {};
49
+ float result {};
56
50
57
51
try
58
52
{
@@ -73,15 +67,13 @@ struct BasicStringConverter<StringType, float>
73
67
};
74
68
75
69
// ==================================================================================================
76
- template <typename StringType >
77
- struct BasicStringConverter <StringType, double >
70
+ template <>
71
+ struct Converter < double >
78
72
{
79
- using value_type = double ;
80
-
81
- static std::optional<value_type> convert (const StringType &value)
73
+ static std::optional<double > convert (const std::string &value)
82
74
{
83
75
std::size_t index = 0 ;
84
- value_type result {};
76
+ double result {};
85
77
86
78
try
87
79
{
@@ -102,15 +94,13 @@ struct BasicStringConverter<StringType, double>
102
94
};
103
95
104
96
// ==================================================================================================
105
- template <typename StringType >
106
- struct BasicStringConverter <StringType, long double >
97
+ template <>
98
+ struct Converter < long double >
107
99
{
108
- using value_type = long double ;
109
-
110
- static std::optional<value_type> convert (const StringType &value)
100
+ static std::optional<long double > convert (const std::string &value)
111
101
{
112
102
std::size_t index = 0 ;
113
- value_type result {};
103
+ long double result {};
114
104
115
105
try
116
106
{
0 commit comments