C++ API
The C++ library is the reference implementation every other reader wraps. It
targets C++20 and lives in the detent namespace.
Targets and Headers
Section titled “Targets and Headers”| CMake target | Header | What it provides |
|---|---|---|
detent::detent | detent/client.hh | Client, InitOptions, HealthSnapshot, Metrics |
detent/model.hh | Snapshot, KnobDef, GroupOverride, GroupRollout, SnapshotPatch | |
detent/result.hh | Result<T, E> | |
detent/errors.hh | KnobError, ErrorCategory, UpdateError, UpdateRejectReason | |
detent/read_view.hh | ClientReadView, ReadSource, EvaluationView | |
detent/global.hh | The process-wide detent::global adapter | |
detent/testing.hh | TestKnobs, TestGuard | |
detent/overrides.hh | OverrideTable, parse_cli_overrides() | |
detent/validation.hh | is_valid_knob_name(), is_valid_group_key() | |
detent::local_client | detent_local/client_source.hh | make_local_read_source() for managed generations |
detent::detent has no networking dependency. Only link
detent::local_client when you use managed generations.
Reference Pages
Section titled “Reference Pages”- Client: construction, reads, views, health and metrics.
- Sources: file, generic and managed-generation sources.
- Global Access and Testing:
the
detent::globaladapter,TestKnobs, and CLI overrides.
Conventions
Section titled “Conventions”- Errors are values on the read path. Reads return
Result<T, KnobError>; only the_or_panichelpers abort. - Errors are exceptions at startup. The
Clientconstructor throws on invalid defaults, invalid CLI overrides, or invalid options. - Optional arguments are
std::optional<std::string_view>. Passstd::nullopt(or nothing) to omit a hash value or switch value. - Nothing on the read path allocates, locks or does I/O.
Result<T, E> is a small std::expected-shaped type, since Detent targets
C++20:
auto r = client.get("search:max_results");if (r) { // or r.has_value() std::int64_t v = r.value();} else { const detent::KnobError& e = r.error(); std::string message = e.what();}