mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-06 10:46:18 +08:00
Added size validation
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user