codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <iostream> #include <boost/foreach.hpp> #include <boost/range/adaptor/map.hpp> #include <QMap> #include <arx/ext/qt/MapForeach.h> int count; class A { public: A(): mValue(0) {} A(int value): mValue(value) {} int value() const { return mValue; } A(const A &other) { count++; mValue = other.mValue; } bool operator<(const A &other) const { return mValue < other.mValue; } private: int mValue; }; int main(int argc, char **argv) { QMap<A, A> m; m.insert(A(1), A(2)); count = 0; BOOST_FOREACH(auto pair, m) { const A &key = pair.first; } std::cout << count << std::endl; count = 0; BOOST_FOREACH(const A &key, m | boost::adaptors::map_keys); std::cout << count << std::endl; return 0; }
Private
[
?
]
Run code
Submit