summaryrefslogtreecommitdiff
path: root/cli-examples/features
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2023-03-20 13:27:25 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2023-03-20 13:55:44 +0300
commit115e8dc4c5042d805ce929530bb10b05d6fbf250 (patch)
treed57e053a395857dff1da348cae7790914091878b /cli-examples/features
parent6e32dd9c26d26bd98bdd074a6d68d1efed95f8df (diff)
Add support for std::multimap
Diffstat (limited to 'cli-examples/features')
-rw-r--r--cli-examples/features/driver.cxx25
-rw-r--r--cli-examples/features/options.cli7
2 files changed, 24 insertions, 8 deletions
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 <boris@codesynthesis.com>
// license : MIT; see accompanying LICENSE file
+#include <utility> // pair
#include <iostream>
#include <iterator>
#include <algorithm>
@@ -45,13 +46,27 @@ main (int argc, char* argv[])
// --map | -m
//
- typedef map<std::string, bool> str_map;
- const str_map& m = o.map ();
- str_map::const_iterator i (m.find ("a"));
+ {
+ typedef map<string, bool> 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<string, int> str_multimap;
+ const str_multimap& m = o.multimap ();
+
+ pair<str_multimap::const_iterator, str_multimap::const_iterator> 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<int> --vector | -v;
std::set<int> --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<std::string, bool> --map | -m;
+ std::multimap<std::string, int> --multimap;
};
}