cppfig 0.1.0
Modern C++20 compile-time type-safe configuration library
Loading...
Searching...
No Matches
cppfig::Validator< T > Class Template Reference

Type-erased validator that can hold any validation function. More...

#include <validator.h>

Public Types

using validator_fn = std::function< ValidationResult(const T &)>
 

Public Member Functions

 Validator ()
 Creates an always-valid validator.
 
 Validator (validator_fn fn)
 Creates a validator from a function.
 
auto operator() (const T &value) const -> ValidationResult
 Validates a value.
 
auto And (Validator< T > other) const -> Validator< T >
 Combines this validator with another (both must pass).
 
auto Or (Validator< T > other) const -> Validator< T >
 Combines this validator with another (either must pass).
 

Detailed Description

template<typename T>
class cppfig::Validator< T >

Type-erased validator that can hold any validation function.

Member Typedef Documentation

◆ validator_fn

template<typename T >
using cppfig::Validator< T >::validator_fn = std::function<ValidationResult(const T&)>

Constructor & Destructor Documentation

◆ Validator() [1/2]

template<typename T >
cppfig::Validator< T >::Validator ( )
inline

Creates an always-valid validator.

◆ Validator() [2/2]

template<typename T >
cppfig::Validator< T >::Validator ( validator_fn  fn)
inlineexplicit

Creates a validator from a function.

Member Function Documentation

◆ And()

template<typename T >
auto cppfig::Validator< T >::And ( Validator< T >  other) const -> Validator<T>
inline

Combines this validator with another (both must pass).

◆ operator()()

template<typename T >
auto cppfig::Validator< T >::operator() ( const T &  value) const -> ValidationResult
inline

Validates a value.

◆ Or()

template<typename T >
auto cppfig::Validator< T >::Or ( Validator< T >  other) const -> Validator<T>
inline

Combines this validator with another (either must pass).


The documentation for this class was generated from the following file: