18std::ostream&
operator<<(std::ostream& os,
const argument_parser&)
noexcept;
30 const std::optional<int> exit_code = std::nullopt,
31 std::ostream& os = std::cout
33 return [&parser, &os, exit_code]() {
34 os << parser << std::endl;
36 std::exit(exit_code.value());
42 return [](
const std::string& file_path) {
43 if (not std::filesystem::exists(file_path))
44 throw std::filesystem::filesystem_error(
45 "File does not exists!",
47 std::make_error_code(std::errc::no_such_file_or_directory)
57template <ap::detail::c_arithmetic T>
59 return [lower_bound](
const T& value) {
60 if (not (value > lower_bound))
61 throw std::out_of_range(
62 std::format(
"Value `{}` must be greater than `{}`!", value, lower_bound)
72template <ap::detail::c_arithmetic T>
74 return [lower_bound](
const T& value) {
75 if (! (value >= lower_bound))
76 throw std::out_of_range(
77 std::format(
"Value `{}` must be greater than or equal to `{}`!", value, lower_bound)
87template <ap::detail::c_arithmetic T>
89 return [upper_bound](
const T& value) {
90 if (! (value < upper_bound))
91 throw std::out_of_range(
92 std::format(
"Value `{}` must be less than `{}`!", value, upper_bound)
102template <ap::detail::c_arithmetic T>
104 return [upper_bound](
const T& value) {
105 if (! (value <= upper_bound))
106 throw std::out_of_range(
107 std::format(
"Value `{}` must be less than or equal to `{}`!", value, upper_bound)
123template <ap::detail::c_arithmetic T,
bool LeftInclusive = true,
bool RightInclusive = true>
125 const T lower_bound,
const T upper_bound
127 return [lower_bound, upper_bound](
const T& value) {
128 constexpr char left_brace = LeftInclusive ?
'[' :
'(';
129 constexpr char right_brace = RightInclusive ?
']' :
')';
131 const bool is_valid =
132 (LeftInclusive ? value >= lower_bound : value > lower_bound)
133 and (RightInclusive ? value <= upper_bound : value < upper_bound);
136 throw std::out_of_range(std::format(
137 "Value `{}` must be in interval {}{}, {}{}!",
Main argument parser class.
detail::callable_type< ap::action_type::observe, T > leq(const T upper_bound) noexcept
Returns an observe action which checks if a parsed value is less than or equal to the given bound.
ap::action_type::on_flag::type print_config(const argument_parser &parser, const std::optional< int > exit_code=std::nullopt, std::ostream &os=std::cout) noexcept
Returns an on-flag action which prints the argument parser's configuration.
detail::callable_type< ap::action_type::observe, T > lt(const T upper_bound) noexcept
Returns an observe action which checks if a parsed value is less than the given bound.
std::ostream & operator<<(std::ostream &os, const argument_parser &) noexcept
detail::callable_type< ap::action_type::observe, T > gt(const T lower_bound) noexcept
Returns an observe action which checks if a parsed value is greater than the given bound.
detail::callable_type< ap::action_type::observe, T > within(const T lower_bound, const T upper_bound) noexcept
Returns an observe action which checks if a parsed value falls within the specified interval.
detail::callable_type< ap::action_type::observe, T > geq(const T lower_bound) noexcept
Returns an observe action which checks if a parsed value is greater than or equal to the given bound.
detail::callable_type< ap::action_type::observe, std::string > check_file_exists() noexcept
Returns an observe action which checks whether lower_bound file with the given name exists.
Defines general action-related utility.
typename AS::template type< T > callable_type
Template argument action callable type alias.