From cffdf8acae2b5f985eeb81cb6e0a5bbd218b9d32 Mon Sep 17 00:00:00 2001 From: Timo Weingärtner Date: Fri, 2 Dec 2011 19:52:02 +0100 Subject: 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. --- hadori.C | 16 +++++++++++++--- 1 file 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 T& begin(pair & ip) { + return ip.first; +} +template T& end(pair & 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; -- cgit v1.2.3