#include #include #include #include #include using namespace std; using namespace boost::adaptors; typedef map my_map_t; my_map_t map_generator() { cout << " Generating map" << endl; my_map_t return_value; return_value["igor!"] = "james"; return_value["12345"] = "ABCDE"; return_value["QWERT"] = "qwert"; return return_value; } void using_temp_ref(const my_map_t &my_map) { BOOST_FOREACH(const string &key, my_map | map_keys) { cout << "key = '" << key << "'" << endl; } } template void using_range_iterator(const boost::iterator_range &keys_range) { BOOST_FOREACH(const string &key, keys_range) { cout << "key = '" << key << "'" << endl; } } int main(int argc, char** argv) { cout << "Test #1 (local variable)" << endl; my_map_t m = map_generator(); BOOST_FOREACH(const string &key, m | map_keys) { cout << "key = '" << key << "'" << endl; } cout << "Test #2 (value_type)" << endl; BOOST_FOREACH(const my_map_t::value_type& p, map_generator()) { cout << "key = '" << p.first << "'" << endl; } cout << "Test #3 (temp ref)" << endl; using_temp_ref(map_generator()); cout << "Test #4 (range_iterator)" << endl; using_range_iterator(map_generator() | map_keys); cout << "Test #5 (bug)" << endl; BOOST_FOREACH(const string &key, map_generator() | map_keys) { cout << "key = '" << key << "'" << endl; } cout << "Test passed!" << endl; }