diff options
author | Timo Weingärtner <timo@tiwe.de> | 2011-12-02 19:52:02 +0100 |
---|---|---|
committer | Timo Weingärtner <timo@tiwe.de> | 2011-12-25 18:48:11 +0100 |
commit | cffdf8acae2b5f985eeb81cb6e0a5bbd218b9d32 (patch) | |
tree | c292f8728f2366b8bb3dd9d1a48fc9fed0792005 /hadori.C | |
parent | 091b33363d0c067c9071414f97fda16102bc065b (diff) | |
download | hadori-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.
Diffstat (limited to 'hadori.C')
-rw-r--r-- | hadori.C | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -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; |