diff --git a/argh.h b/argh.h index 5c1d1cb..c62b023 100644 --- a/argh.h +++ b/argh.h @@ -9,6 +9,14 @@ #include #include +#if __cplusplus >= 201703L && __has_include( ) +# include // for library features tests +#endif + +#if defined( __cpp_lib_ranges ) +# include +#endif + namespace argh { // Terminology: @@ -121,6 +129,9 @@ namespace argh std::multiset const& flags() const { return flags_; } std::multimap const& params() const { return params_; } multimap_iteration_wrapper params(std::string const& name) const; +#if defined( __cpp_lib_ranges ) + auto params(std::initializer_list init_list) const; +#endif std::vector const& pos_args() const { return pos_args_; } // begin() and end() for using range-for over positional args. @@ -482,4 +493,17 @@ namespace argh auto trimmed_name = trim_leading_dashes(name); return multimap_iteration_wrapper(params_.lower_bound(trimmed_name), params_.upper_bound(trimmed_name)); } + + ////////////////////////////////////////////////////////////////////////// + +#if defined( __cpp_lib_ranges ) + inline auto parser::params(std::initializer_list init_list) const + { + return std::ranges::subrange( init_list.begin(), init_list.end() ) | + std::views::transform( [ this ]( char const * const name ) -> multimap_iteration_wrapper { + return this->params( std::string( name ) ); + } ) | + std::views::join; + } +#endif }