15 template <
typename T,
typename... Types>
16 struct IsOneOf : std::disjunction<std::is_same<T, Types>...> { };
22 consteval auto IsPathPrefix(std::string_view prefix, std::string_view path) ->
bool
24 return path.size() > prefix.size() && path.starts_with(prefix) && path[prefix.size()] ==
'.';
33 if (path.empty() || path.front() ==
'.' || path.back() ==
'.') {
36 for (std::size_t i = 1; i < path.size(); ++i) {
37 if (path[i] ==
'.' && path[i - 1] ==
'.') {
45 template <
typename... Settings>
48 constexpr std::array<std::string_view,
sizeof...(Settings)> paths = { Settings::path... };
49 for (
auto path : paths) {
64 template <
typename... Settings>
67 constexpr std::array<std::string_view,
sizeof...(Settings)> paths = { Settings::path... };
68 for (std::size_t i = 0; i < paths.size(); ++i) {
69 for (std::size_t j = i + 1; j < paths.size(); ++j) {
104template <IsSetting... Settings>
107 static constexpr std::size_t
size =
sizeof...(Settings);
110 "Every path in ConfigSchema must be non-empty and free of empty dot-separated segments");
113 "All paths in ConfigSchema must be unique, and none may be a prefix of another");
116 template <
typename S>
120 [[nodiscard]]
static constexpr auto GetPaths() -> std::array<std::string_view, size>
122 return { Settings::path... };
126 [[nodiscard]]
static constexpr auto Size() -> std::size_t {
return size; }
132 template <
typename Fn>
135 (fn.template operator()<Settings>(), ...);
140template <IsSetting S>
Configuration schema holding all setting types.
Definition schema.h:105
static constexpr bool has_setting
Checks if a setting type is in this schema.
Definition schema.h:117
static constexpr std::size_t size
Definition schema.h:107
static constexpr auto Size() -> std::size_t
Returns the number of settings in the schema.
Definition schema.h:126
static void ForEachSetting(Fn &&fn)
Iterates over all setting types with a callable.
Definition schema.h:133
static constexpr auto GetPaths() -> std::array< std::string_view, size >
Returns all paths as a compile-time array.
Definition schema.h:120
consteval auto AllPathsWellFormed() -> bool
Helper to check that every path is well-formed at compile time.
Definition schema.h:46
consteval auto AllPathsUnique() -> bool
Helper to check if all paths are unique at compile time.
Definition schema.h:65
consteval auto IsPathPrefix(std::string_view prefix, std::string_view path) -> bool
Returns true if prefix names an ancestor of path.
Definition schema.h:22
consteval auto IsPathWellFormed(std::string_view path) -> bool
Returns true if path is a non-empty dot-separated path with no empty segments.
Definition schema.h:31
C++20 compile-time type-safe configuration library.
Definition conf.h:17
typename S::value_type setting_value_type
Helper alias to get the value type for a setting.
Definition schema.h:141
Helper to check if a type is in a parameter pack.
Definition schema.h:16