There are more efficient ways to iterate over std::map keys (or any container whose value_type is pair<T,U> ), namely Boost.Range map_keys adapter (there is also map_values one there):
#include <boost/range/adaptor/map.hpp> #include <utility> #include <vector> #include <iostream> int main(){ typedef std::pair<int, int> Pair; std::vector<Pair> v {Pair(1,2), Pair(2,3)}; for(auto& first : v | boost::adaptors::map_keys){ std::cout << first << " "; } }
But back to your problem: all Boost libraries use the Boost.Utility result_of function , which will not return to std::result_of for any reason, and also will not use decltype if it is available if you do not report it. You do this by putting #define BOOST_RESULT_OF_USE_DECLTYPE before turning on the first Boost.
This, however, did not compile your code using Clang 3.1 SVN + libC ++. Here is the code I used:
#define BOOST_RESULT_OF_USE_DECLTYPE #include <boost/iterator/transform_iterator.hpp> #include <utility> #include <vector> #include <functional> int main(){ typedef std::pair<int, int> Pair; std::vector<Pair> v {Pair(1,2), Pair(2,3)}; using namespace std::placeholders; auto choose_first = std::bind(&Pair::first, _1); boost::make_transform_iterator(v.begin(), choose_first); }
Compiled with
clang++ -std=c++0x -stdlib=libc++ -Wall -pedantic -Ipath/to/boost -Wno-mismatched-tags t.cpp
GCC 4.7 seems to agree with this just fine, so I assume this is a bug in libC ++.
source share