30 std::optional<ParseError>
error;
32 [[nodiscard]]
auto ok() const noexcept ->
bool {
return !
error.has_value(); }
33 [[nodiscard]]
explicit operator bool() const noexcept {
return ok(); }
40 return a.ok() ? std::move(b) : std::move(a);
45 return a.ok() ? std::move(a) : std::move(b);
52concept NamedProviderArg =
requires(
const T& t) {
53 { t.provided() } -> std::convertible_to<bool>;
55 std::remove_cvref_t<T>::name.view()
56 } -> std::convertible_to<std::string_view>;
59template <NamedProviderArg... Args>
60auto names_list(
const Args&...) -> std::string {
63 (..., (s += (first ? std::string{} : std::string{
", "}) +
"--" +
64 std::string(std::remove_cvref_t<Args>::name.view()),
92template <detail::NamedProviderArg... Args>
94 int count = (0 + ... + (args.provided() ? 1 : 0));
96 auto subject = detail::names_list(args...);
102 .detail =
"exactly one of these options must be provided",
109 .detail =
"exactly one of these options must be provided, but multiple "
119template <detail::NamedProviderArg... Args>
121 int count = (0 + ... + (args.provided() ? 1 : 0));
126 .subject = detail::names_list(args...),
127 .detail =
"at most one of these options may be provided",
136template <detail::NamedProviderArg... Args>
138 bool all = (... && args.provided());
143 .subject = detail::names_list(args...),
144 .detail =
"all of these options must be provided",
153template <detail::NamedProviderArg... Args>
155 int count = (0 + ... + (args.provided() ? 1 : 0));
156 constexpr int total =
static_cast<int>(
sizeof...(Args));
161 .subject = detail::names_list(args...),
162 .detail =
"either all of these options must be provided, or none",
172template <detail::NamedProv
iderArg Cond, detail::NamedProv
iderArg Req>
175 if (!condition.provided() ||
required.provided())
180 .subject =
"--" + std::string(std::remove_cvref_t<Req>::name.view()),
181 .detail =
"required when --" +
182 std::string(std::remove_cvref_t<Cond>::name.view()) +
Post-parse constraint helpers.
auto one_of(const Args &... args) -> ConstraintResult
Exactly one of the listed options must be provided.
auto at_most_one_of(const Args &... args) -> ConstraintResult
At most one of the listed options may be provided.
auto all_of(const Args &... args) -> ConstraintResult
All of the listed options must be provided.
auto requires_if(const Cond &condition, const Req &required) -> ConstraintResult
If condition is provided, required must also be provided.
auto all_or_none(const Args &... args) -> ConstraintResult
Either all of the listed options must be provided, or none.
constexpr auto ok() -> ActionResult< void >
Helper function for constructing a successful ActionResult<void>.
constexpr auto required
Convenience constant for Presence::required.
@ dependency_missing
An option that depends on another option was given without it.
@ mutually_exclusive
Two mutually-exclusive options were both supplied.
@ missing_required
A required option or positional was not provided.
The result type returned by a constraints() post-parse hook.
friend auto operator&&(ConstraintResult a, ConstraintResult b) -> ConstraintResult
static auto pass() -> ConstraintResult
friend auto operator||(ConstraintResult a, ConstraintResult b) -> ConstraintResult
auto ok() const noexcept -> bool
std::optional< ParseError > error
static auto fail(ParseError e) -> ConstraintResult
Carries all context about a single parse/validation failure.