11#ifndef RFL_COMPARISONS_HPP_
22#define RFL_COMPARISONS_HPP_
33
4+ #include < sstream>
45#include < type_traits>
56
67#include " Result.hpp"
@@ -14,9 +15,10 @@ struct EqualTo {
1415 static Result<T> validate (T _value) noexcept {
1516 constexpr auto threshold = static_cast <T>(_threshold);
1617 if (_value != threshold) {
17- return error (" Value expected to be equal to " +
18- std::to_string (threshold) + " , but got " +
19- std::to_string (_value) + " ." );
18+ std::stringstream stream;
19+ stream << " Value expected to be equal to " << threshold << " , but got "
20+ << _value << " ." ;
21+ return error (stream.str ());
2022 }
2123 return _value;
2224 }
@@ -38,9 +40,10 @@ struct Minimum {
3840 static Result<T> validate (T _value) noexcept {
3941 constexpr auto threshold = static_cast <T>(_threshold);
4042 if (_value < threshold) {
41- return error (" Value expected to be greater than or equal to " +
42- std::to_string (threshold) + " , but got " +
43- std::to_string (_value) + " ." );
43+ std::stringstream stream;
44+ stream << " Value expected to be greater than or equal to " << threshold
45+ << " , but got " << _value << " ." ;
46+ return error (stream.str ());
4447 }
4548 return _value;
4649 }
@@ -62,9 +65,10 @@ struct ExclusiveMinimum {
6265 static Result<T> validate (T _value) noexcept {
6366 constexpr auto threshold = static_cast <T>(_threshold);
6467 if (_value <= threshold) {
65- return error (" Value expected to be greater than " +
66- std::to_string (threshold) + " , but got " +
67- std::to_string (_value) + " ." );
68+ std::stringstream stream;
69+ stream << " Value expected to be greater than " << threshold
70+ << " , but got " << _value << " ." ;
71+ return error (stream.str ());
6872 }
6973 return _value;
7074 }
@@ -86,9 +90,10 @@ struct Maximum {
8690 static Result<T> validate (T _value) noexcept {
8791 constexpr auto threshold = static_cast <T>(_threshold);
8892 if (_value > threshold) {
89- return error (" Value expected to be less than or equal to " +
90- std::to_string (threshold) + " , but got " +
91- std::to_string (_value) + " ." );
93+ std::stringstream stream;
94+ stream << " Value expected to be less than or equal to " << threshold
95+ << " , but got " << _value << " ." ;
96+ return error (stream.str ());
9297 }
9398 return _value;
9499 }
@@ -110,9 +115,10 @@ struct ExclusiveMaximum {
110115 static Result<T> validate (T _value) noexcept {
111116 constexpr auto threshold = static_cast <T>(_threshold);
112117 if (_value >= threshold) {
113- return error (" Value expected to be less than " +
114- std::to_string (threshold) + " , but got " +
115- std::to_string (_value) + " ." );
118+ std::stringstream stream;
119+ stream << " Value expected to be less than " << threshold << " , but got "
120+ << _value << " ." ;
121+ return error (stream.str ());
116122 }
117123 return _value;
118124 }
@@ -134,9 +140,10 @@ struct NotEqualTo {
134140 static Result<T> validate (T _value) noexcept {
135141 constexpr auto threshold = static_cast <T>(_threshold);
136142 if (_value == threshold) {
137- return error (" Value expected to not be equal to " +
138- std::to_string (threshold) + " , but got " +
139- std::to_string (_value) + " ." );
143+ std::stringstream stream;
144+ stream << " Value expected not to be equal to " << threshold
145+ << " , but got " << _value << " ." ;
146+ return error (stream.str ());
140147 }
141148 return _value;
142149 }
0 commit comments