Added some standard methods to the validator

This commit is contained in:
Patrick Urbanke
2023-11-06 23:44:30 +01:00
parent 91cba55edb
commit d75fc3d5b6
+16
View File
@@ -30,6 +30,10 @@ struct Validator {
Validator() : value_(V::validate(T()).value()) {}
Validator(Validator<T, V>&& _other) noexcept = default;
Validator(const Validator<T, V>& _other) = default;
Validator(const T& _value) : value_(V::validate(_value).value()) {}
template <class U, typename std::enable_if<std::is_convertible_v<U, T>,
@@ -44,6 +48,18 @@ struct Validator {
return *this;
}
/// Assigns the underlying object.
auto& operator=(T&& _value) {
value_ = V::validate(_value).value();
return *this;
}
/// Assigns the underlying object.
Validator<T, V>& operator=(const Validator<T, V>& _other) = default;
/// Assigns the underlying object.
Validator<T, V>& operator=(Validator<T, V>&& _other) = default;
/// Assigns the underlying object.
template <class U, typename std::enable_if<std::is_convertible_v<U, T>,
bool>::type = true>