summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Weingärtner <timo@tiwe.de>2011-12-02 19:52:02 +0100
committerTimo Weingärtner <timo@tiwe.de>2011-12-25 18:48:11 +0100
commitcffdf8acae2b5f985eeb81cb6e0a5bbd218b9d32 (patch)
treec292f8728f2366b8bb3dd9d1a48fc9fed0792005
parent091b33363d0c067c9071414f97fda16102bc065b (diff)
downloadhadori-cffdf8acae2b5f985eeb81cb6e0a5bbd218b9d32.tar.gz
use equal_range and range-for
needs an adapter because std::multimap doesn't deliver begin() and end() for a std::pair of its iterators.
-rw-r--r--hadori.C16
1 files changed, 13 insertions, 3 deletions
diff --git a/hadori.C b/hadori.C
index 1e4ea7b..7597530 100644
--- a/hadori.C
+++ b/hadori.C
@@ -19,6 +19,16 @@ namespace po = boost::program_options;
#include "inode.h"
+// needed for equal_range and range-for
+namespace std {
+template<typename T> T& begin(pair<T,T> & ip) {
+ return ip.first;
+}
+template<typename T> T& end(pair<T,T> & ip) {
+ return ip.second;
+}
+}
+
po::variables_map config;
std::ostream debug(std::clog.rdbuf()), verbose(std::clog.rdbuf()), error(std::clog.rdbuf());
@@ -64,8 +74,8 @@ void handle_file(std::string const & path, struct stat const & s) {
}
inode f(path, s);
debug << f << " is new to us" << std::endl;
- for (auto it = sizes.lower_bound(s.st_size); it != sizes.upper_bound(s.st_size); ++it) {
- inode const & candidate = kept.find(it->second)->second;
+ for (auto const & it : sizes.equal_range(s.st_size)) {
+ inode const & candidate = kept.find(it.second)->second;
debug << "looking if it matches " << candidate << std::endl;
if (candidate.stat.st_mode != s.st_mode)
continue;
@@ -83,7 +93,7 @@ void handle_file(std::string const & path, struct stat const & s) {
continue;
verbose << "linking " << candidate << " to " << path << std::endl;
if (s.st_nlink > 1)
- to_link.insert(std::make_pair(s.st_ino, it->second));
+ to_link.insert(std::make_pair(s.st_ino, it.second));
if (not config.count("dry-run"))
do_link(candidate, path);
return;