From 115e8dc4c5042d805ce929530bb10b05d6fbf250 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 20 Mar 2023 13:27:25 +0300 Subject: Add support for std::multimap --- cli-examples/features/driver.cxx | 25 ++++++++++++++++++++----- cli-examples/features/options.cli | 7 ++++--- 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'cli-examples/features') diff --git a/cli-examples/features/driver.cxx b/cli-examples/features/driver.cxx index a6299b9..fc364a0 100644 --- a/cli-examples/features/driver.cxx +++ b/cli-examples/features/driver.cxx @@ -2,6 +2,7 @@ // author : Boris Kolpackov // license : MIT; see accompanying LICENSE file +#include // pair #include #include #include @@ -45,13 +46,27 @@ main (int argc, char* argv[]) // --map | -m // - typedef map str_map; - const str_map& m = o.map (); - str_map::const_iterator i (m.find ("a")); + { + typedef map str_map; + const str_map& m = o.map (); + str_map::const_iterator i (m.find ("a")); - if (i != m.end ()) - cerr << "value for the 'a' key: " << i->second << endl; + if (i != m.end ()) + cerr << "value for the 'a' map key: " << i->second << endl; + } + // --multimap + // + { + typedef multimap str_multimap; + const str_multimap& m = o.multimap (); + + pair r ( + m.equal_range ("a")); + + for (str_multimap::const_iterator i (r.first); i != r.second; ++i) + cerr << "value for the 'a' multimap key: " << i->second << endl; + } } catch (const cli::exception& e) { diff --git a/cli-examples/features/options.cli b/cli-examples/features/options.cli index 4065830..d1e4b0c 100644 --- a/cli-examples/features/options.cli +++ b/cli-examples/features/options.cli @@ -30,10 +30,11 @@ namespace features std::vector --vector | -v; std::set --set | -s; - // We can also use maps. In this case the option value is expected to have - // two parts: the key and the value, separated by '='. For example: -m a=1 - // -m =true -m c= -m d (same as -m d=). + // We can also use maps and multimaps. In this case the option value is + // expected to have two parts: the key and the value, separated by '='. + // For example: -m a=1 -m =true -m c= -m d (same as -m d=). // std::map --map | -m; + std::multimap --multimap; }; } -- cgit v1.1