@@ -88,10 +88,14 @@ class Writer {
88
88
const T& _var) const noexcept {
89
89
if constexpr (std::is_same<std::remove_cvref_t <T>, std::string>() ||
90
90
std::is_same<std::remove_cvref_t <T>, bool >() ||
91
- std::is_floating_point<std::remove_cvref_t <T>>() ||
92
91
std::is_same<std::remove_cvref_t <T>,
93
92
std::remove_cvref_t <decltype (YAML::Null)>>()) {
94
93
(*out_) << YAML::Key << _name.data () << YAML::Value << _var;
94
+ } else if constexpr (std::is_floating_point<std::remove_cvref_t <T>>()) {
95
+ // std::to_string is necessary to ensure that floating point values are
96
+ // always written as floats.
97
+ (*out_) << YAML::Key << _name.data () << YAML::Value
98
+ << std::to_string (_var);
95
99
} else if constexpr (std::is_integral<std::remove_cvref_t <T>>()) {
96
100
(*out_) << YAML::Key << _name.data () << YAML::Value
97
101
<< static_cast <int64_t >(_var);
@@ -103,7 +107,20 @@ class Writer {
103
107
104
108
template <class T >
105
109
OutputVarType insert_value (const T& _var) const noexcept {
106
- (*out_) << _var;
110
+ if constexpr (std::is_same<std::remove_cvref_t <T>, std::string>() ||
111
+ std::is_same<std::remove_cvref_t <T>, bool >() ||
112
+ std::is_same<std::remove_cvref_t <T>,
113
+ std::remove_cvref_t <decltype (YAML::Null)>>()) {
114
+ (*out_) << _var;
115
+ } else if constexpr (std::is_floating_point<std::remove_cvref_t <T>>()) {
116
+ // std::to_string is necessary to ensure that floating point values are
117
+ // always written as floats.
118
+ (*out_) << std::to_string (_var);
119
+ } else if constexpr (std::is_integral<std::remove_cvref_t <T>>()) {
120
+ (*out_) << static_cast <int64_t >(_var);
121
+ } else {
122
+ static_assert (rfl::always_false_v<T>, " Unsupported type." );
123
+ }
107
124
return OutputVarType{};
108
125
}
109
126
0 commit comments