mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-06 18:56:19 +08:00
This commit is contained in:
+25
-18
@@ -1,6 +1,7 @@
|
||||
#ifndef RFL_COMPARISONS_HPP_
|
||||
#define RFL_COMPARISONS_HPP_
|
||||
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
|
||||
#include "Result.hpp"
|
||||
@@ -14,9 +15,10 @@ struct EqualTo {
|
||||
static Result<T> validate(T _value) noexcept {
|
||||
constexpr auto threshold = static_cast<T>(_threshold);
|
||||
if (_value != threshold) {
|
||||
return error("Value expected to be equal to " +
|
||||
std::to_string(threshold) + ", but got " +
|
||||
std::to_string(_value) + ".");
|
||||
std::stringstream stream;
|
||||
stream << "Value expected to be equal to " << threshold << ", but got "
|
||||
<< _value << ".";
|
||||
return error(stream.str());
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
@@ -38,9 +40,10 @@ struct Minimum {
|
||||
static Result<T> validate(T _value) noexcept {
|
||||
constexpr auto threshold = static_cast<T>(_threshold);
|
||||
if (_value < threshold) {
|
||||
return error("Value expected to be greater than or equal to " +
|
||||
std::to_string(threshold) + ", but got " +
|
||||
std::to_string(_value) + ".");
|
||||
std::stringstream stream;
|
||||
stream << "Value expected to be greater than or equal to " << threshold
|
||||
<< ", but got " << _value << ".";
|
||||
return error(stream.str());
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
@@ -62,9 +65,10 @@ struct ExclusiveMinimum {
|
||||
static Result<T> validate(T _value) noexcept {
|
||||
constexpr auto threshold = static_cast<T>(_threshold);
|
||||
if (_value <= threshold) {
|
||||
return error("Value expected to be greater than " +
|
||||
std::to_string(threshold) + ", but got " +
|
||||
std::to_string(_value) + ".");
|
||||
std::stringstream stream;
|
||||
stream << "Value expected to be greater than " << threshold
|
||||
<< ", but got " << _value << ".";
|
||||
return error(stream.str());
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
@@ -86,9 +90,10 @@ struct Maximum {
|
||||
static Result<T> validate(T _value) noexcept {
|
||||
constexpr auto threshold = static_cast<T>(_threshold);
|
||||
if (_value > threshold) {
|
||||
return error("Value expected to be less than or equal to " +
|
||||
std::to_string(threshold) + ", but got " +
|
||||
std::to_string(_value) + ".");
|
||||
std::stringstream stream;
|
||||
stream << "Value expected to be less than or equal to " << threshold
|
||||
<< ", but got " << _value << ".";
|
||||
return error(stream.str());
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
@@ -110,9 +115,10 @@ struct ExclusiveMaximum {
|
||||
static Result<T> validate(T _value) noexcept {
|
||||
constexpr auto threshold = static_cast<T>(_threshold);
|
||||
if (_value >= threshold) {
|
||||
return error("Value expected to be less than " +
|
||||
std::to_string(threshold) + ", but got " +
|
||||
std::to_string(_value) + ".");
|
||||
std::stringstream stream;
|
||||
stream << "Value expected to be less than " << threshold << ", but got "
|
||||
<< _value << ".";
|
||||
return error(stream.str());
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
@@ -134,9 +140,10 @@ struct NotEqualTo {
|
||||
static Result<T> validate(T _value) noexcept {
|
||||
constexpr auto threshold = static_cast<T>(_threshold);
|
||||
if (_value == threshold) {
|
||||
return error("Value expected to not be equal to " +
|
||||
std::to_string(threshold) + ", but got " +
|
||||
std::to_string(_value) + ".");
|
||||
std::stringstream stream;
|
||||
stream << "Value expected not to be equal to " << threshold
|
||||
<< ", but got " << _value << ".";
|
||||
return error(stream.str());
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user