Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions argh.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
#include <map>
#include <cassert>

#if __cplusplus >= 201703L && __has_include( <version> )
# include <version> // for library features tests
#endif

#if defined( __cpp_lib_ranges )
# include <ranges>
#endif

namespace argh
{
// Terminology:
Expand Down Expand Up @@ -121,6 +129,9 @@ namespace argh
std::multiset<std::string> const& flags() const { return flags_; }
std::multimap<std::string, std::string> const& params() const { return params_; }
multimap_iteration_wrapper params(std::string const& name) const;
#if defined( __cpp_lib_ranges )
auto params(std::initializer_list<char const* const> init_list) const;
#endif
std::vector<std::string> const& pos_args() const { return pos_args_; }

// begin() and end() for using range-for over positional args.
Expand Down Expand Up @@ -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<char const* const> 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
}