cppfig 0.1.0
Modern C++20 compile-time type-safe configuration library
Loading...
Searching...
No Matches
cppfig::IsSetting Concept Reference

Concept for valid setting types. More...

#include <setting.h>

Concept definition

template<typename S>
concept cppfig::IsSetting = requires {
{ S::path } -> std::convertible_to<std::string_view>;
typename S::value_type;
{ S::default_value() } -> std::same_as<typename S::value_type>;
} && Configurable<typename S::value_type>
Concept for valid setting types.
Definition setting.h:35

Detailed Description

Concept for valid setting types.

A type satisfies IsSetting if it provides all required static members and functions for configuration management.

Required:

  • path: std::string_view with the hierarchical key path
  • value_type: The type of the setting value
  • default_value(): Static function returning the default value

Optional:

  • env_override: std::string_view with environment variable name
  • validator(): Static function returning a Validator<value_type>

Example:

struct ServerHost {
static constexpr std::string_view path = "server.host";
static constexpr std::string_view env_override = "SERVER_HOST";
using value_type = std::string;
static auto default_value() -> value_type { return "localhost"; }
static auto validator() -> Validator<value_type> { return NotEmpty(); }
};
Type-erased validator that can hold any validation function.
Definition validator.h:33
auto NotEmpty() -> Validator< std::string >
Creates a validator that checks if a string is not empty.
Definition validator.h:145