cppfig 0.1.0
Modern C++20 compile-time type-safe configuration library
Loading...
Searching...
No Matches
validator.h File Reference
#include <concepts>
#include <functional>
#include <string>
#include <type_traits>
#include <vector>
Include dependency graph for validator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cppfig::ValidationResult
 Result of a validation operation. More...
 
class  cppfig::Validator< T >
 Type-erased validator that can hold any validation function. More...
 

Namespaces

namespace  cppfig
 C++20 compile-time type-safe configuration library.
 

Concepts

concept  cppfig::ValidatorFor
 Concept for validator types.
 

Functions

template<typename T >
requires std::is_arithmetic_v<T>
auto cppfig::Min (T min_value) -> Validator< T >
 Creates a validator that checks if a numeric value is at least min.
 
template<typename T >
requires std::is_arithmetic_v<T>
auto cppfig::Max (T max_value) -> Validator< T >
 Creates a validator that checks if a numeric value is at most max.
 
template<typename T >
requires std::is_arithmetic_v<T>
auto cppfig::Range (T min_value, T max_value) -> Validator< T >
 Creates a validator that checks if a numeric value is within [min, max].
 
template<typename T >
requires std::is_arithmetic_v<T>
auto cppfig::Positive () -> Validator< T >
 Creates a validator that checks if a numeric value is positive.
 
template<typename T >
requires std::is_arithmetic_v<T>
auto cppfig::NonNegative () -> Validator< T >
 Creates a validator that checks if a numeric value is non-negative.
 
auto cppfig::NotEmpty () -> Validator< std::string >
 Creates a validator that checks if a string is not empty.
 
auto cppfig::MaxLength (std::size_t max_len) -> Validator< std::string >
 Creates a validator that checks if a string length is at most max.
 
auto cppfig::MinLength (std::size_t min_len) -> Validator< std::string >
 Creates a validator that checks if a string length is at least min.
 
template<typename T >
auto cppfig::OneOf (std::vector< T > allowed_values) -> Validator< T >
 Creates a validator that checks if a value is one of the allowed values.
 
template<typename T , typename Pred >
requires std::predicate<Pred, const T&>
auto cppfig::Predicate (Pred pred, std::string error_message) -> Validator< T >
 Creates a validator from a predicate function.
 
template<typename T >
auto cppfig::AlwaysValid () -> Validator< T >
 Creates an always-valid validator.