Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/libbash:master commit in: test/
Date: Sat, 02 Apr 2011 15:51:03
Message-Id: 2a3efed81037df11a5d338503713092e3ef0237c.betelgeuse@gentoo
1 commit: 2a3efed81037df11a5d338503713092e3ef0237c
2 Author: Petteri Räty <petsku <AT> petteriraty <DOT> eu>
3 AuthorDate: Sat Apr 2 15:30:50 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Sat Apr 2 15:46:51 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=2a3efed8
7
8 Use std::map to simplify variable printer
9
10 std::map is sorted so we can simplify the code by just creating a map
11 from the unsorted_map.
12
13 ---
14 test/variable_printer.cpp | 12 ++++--------
15 1 files changed, 4 insertions(+), 8 deletions(-)
16
17 diff --git a/test/variable_printer.cpp b/test/variable_printer.cpp
18 index ab2b4cb..b519d3f 100644
19 --- a/test/variable_printer.cpp
20 +++ b/test/variable_printer.cpp
21 @@ -24,11 +24,9 @@
22
23 #include <algorithm>
24 #include <iostream>
25 -#include <vector>
26 +#include <map>
27
28 -#include <boost/range/adaptor/map.hpp>
29 #include <boost/range/algorithm/for_each.hpp>
30 -#include <boost/range/algorithm/sort.hpp>
31 #include <gtest/gtest.h>
32
33 #include "libbash.h"
34 @@ -46,11 +44,9 @@ int main(int argc, char** argv)
35 unordered_map<string, string> variables;
36 libbash::interpret(argv[1], variables);
37
38 - auto keys = variables | boost::adaptors::map_keys;
39 - vector<string> names(keys.begin(), keys.end());
40 - auto sorted = boost::sort(names);
41 - boost::for_each(boost::sort(names), [&](const string& key){
42 - cout << key << '=' << variables[key] << endl;
43 + std::map<string, string> sorted(variables.begin(), variables.end());
44 + boost::for_each(sorted, [&](const std::pair<string,string>& pair){
45 + cout << pair.first << '=' << pair.second << endl;
46 });
47
48 return 0;