23#ifndef TCLAP_PREDICATE_CONSTRAINT_H
24#define TCLAP_PREDICATE_CONSTRAINT_H
43 : _description(std::move(
description)), _shortId(std::move(shortId)) {}
45 template <
class Function>
49 template <
class Function>
50 std::string
shortID(
const Function &)
const {
55 std::string _description;
61 requires requires(
const Rule &rule) {
62 { rule.
description() } -> std::convertible_to<std::string>;
65 return rule.description();
68 requires requires(
const Rule &rule) {
69 { rule.shortID() } -> std::convertible_to<std::string>;
71 std::string
shortID(
const Rule &rule)
const {
72 return rule.shortID();
78template <
class Function>
81template <
class Signature>
84template <
class Function>
86 if constexpr ((std::is_pointer_v<Function> &&
87 std::is_function_v<std::remove_pointer_t<Function>>) ||
88 std::is_member_pointer_v<Function> ||
91 throw std::invalid_argument(
92 "PredicateConstraint requires a non-empty callable");
96template <
class T,
class Function,
class Text>
98 std::predicate<const Function &, const T &> &&
99 requires(
const Text &text,
const Function &function) {
100 { text.description(function) } -> std::convertible_to<std::string>;
101 { text.shortID(function) } -> std::convertible_to<std::string>;
121template <
class T,
class Function = std::function<
bool(const T &)>,
122 class Text =
internal::FixedConstra
intText>
130 requires std::constructible_from<Function, F &&> &&
131 std::constructible_from<Text, std::string, std::string>
134 : _function(std::forward<F>(function)),
135 _text(std::move(
description), std::move(shortId)) {
142 requires std::constructible_from<Function, F &&>
144 : _function(std::forward<F>(function)), _text(std::move(text)) {
154 bool check(
const T &value)
const override {
155 return std::invoke(_function, value);
158 return _text.description(_function);
160 [[nodiscard]] std::string
shortID()
const override {
161 return _text.shortID(_function);
175template <
class T,
class Function>
176 requires std::predicate<const std::decay_t<Function> &,
const T &>
178 Function &&function) {
180 std::move(description), std::move(shortId),
181 std::forward<Function>(function));
189template <
class T,
class Rule>
190 requires std::predicate<const std::decay_t<Rule> &,
const T &> &&
191 requires(
const std::decay_t<Rule> &rule) {
192 { rule.
description() } -> std::convertible_to<std::string>;
193 { rule.shortID() } -> std::convertible_to<std::string>;
The interface that defines the interaction between the Arg and Constraint.
Adapts an owned function or const function object to Constraint<T>.
PredicateConstraint(std::string description, std::string shortId, F &&function)
Owns the callable and separate presentation strings.
PredicateConstraint & operator=(PredicateConstraint &&)=default
std::string description() const override
Returns a description of the Constraint.
PredicateConstraint(const PredicateConstraint &)=default
bool check(const T &value) const override
The method used to verify that the value parsed from the command line meets the constraint.
~PredicateConstraint() override=default
PredicateConstraint & operator=(const PredicateConstraint &)=default
std::string shortID() const override
Returns the short ID for the Constraint.
PredicateConstraint(PredicateConstraint &&)=default
PredicateConstraint(F &&function, Text text)
Advanced form used by the rule factory to share validation/text state.
FixedConstraintText(std::string description, std::string shortId)
std::string description(const Function &) const
std::string shortID(const Function &) const
void ValidateConstraintPredicate(const Function &function)
auto MakeConstraint(std::string description, std::string shortId, Function &&function)
Creates an owning constraint with fixed presentation text.
auto MakeRuleConstraint(Rule &&rule)
Creates an owning rule constraint.
std::string shortID(const Rule &rule) const
std::string description(const Rule &rule) const