Added size validation

This commit is contained in:
Patrick Urbanke
2023-11-02 22:53:58 +01:00
parent a2a6609466
commit fcaf2e8e23
7 changed files with 83 additions and 146 deletions
+22
View File
@@ -0,0 +1,22 @@
#ifndef RFL_SIZE_HPP_
#define RFL_SIZE_HPP_
#include "rfl/Result.hpp"
namespace rfl {
template <class V>
struct Size {
template <class T>
static rfl::Result<T> validate(const T& _t) {
const auto to_t = [&](const auto& _v) { return _t; };
const auto embellish_error = [](const auto& _err) {
return Error("Size validation failed: " + _err.what());
};
return V::validate(_t.size()).transform(to_t).or_else(embellish_error);
}
};
} // namespace rfl
#endif