23#ifndef TCLAP_PREDICATE_CONSTRAINT_H
24#define TCLAP_PREDICATE_CONSTRAINT_H
38 const std::string &shortId)
41 template <
class Function>
45 template <
class Function>
46 std::string
shortID(
const Function &)
const {
51 std::string _description;
58 return rule.description();
61 std::string
shortID(
const Rule &rule)
const {
62 return rule.shortID();
68template <
class Function>
70 template <
class Actual>
71 static void check(
const Actual &) {}
74template <
class Function>
77template <
class Function>
80template <
class Function>
84template <
class Result,
class Argument>
86 static void check(Result (*function)(Argument)) {
88 throw std::invalid_argument(
89 "PredicateConstraint requires a non-empty callable");
95#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
96template <
class Result,
class Argument>
97struct ValidateConstraintPredicate<Result (*)(Argument)
noexcept> {
98 static void check(Result (*function)(Argument)
noexcept) {
100 throw std::invalid_argument(
101 "PredicateConstraint requires a non-empty callable");
122template <
class T,
class Function = bool (*)(
const T &),
123 class Text = internal::FixedConstraintText>
130 const std::string &shortId,
const Function &function)
131 : _function(function), _text(description, shortId) {
138 : _function(function), _text(text) {
144 bool check(
const T &value)
const {
return _function(value); }
145 std::string
description()
const {
return _text.description(_function); }
146 std::string
shortID()
const {
return _text.shortID(_function); }
158template <
class T,
class Function>
160 const std::string &shortId,
170template <
class T,
class Rule>
The interface that defines the interaction between the Arg and Constraint.
Adapts an owned function or const function object to Constraint<T>.
virtual ~PredicateConstraint()
std::string shortID() const
Returns the short ID for the Constraint.
bool check(const T &value) const
The method used to verify that the value parsed from the command line meets the constraint.
std::string description() const
Returns a description of the Constraint.
PredicateConstraint(const std::string &description, const std::string &shortId, const Function &function)
Copies the callable and the two independently supplied strings.
PredicateConstraint(const Function &function, const Text &text)
Advanced form used by the rule factory to share validation/text state.
FixedConstraintText(const std::string &description, const std::string &shortId)
std::string description(const Function &) const
std::string shortID(const Function &) const
PredicateConstraint< T, Function > MakeConstraint(const std::string &description, const std::string &shortId, Function function)
Creates an owning constraint with fixed presentation text.
PredicateConstraint< T, Rule, internal::RuleConstraintText > MakeRuleConstraint(Rule rule)
Creates an owning rule constraint.
std::string description(const Rule &rule) const
std::string shortID(const Rule &rule) const
static void check(Result(*function)(Argument))
static void check(const Actual &)