iterator adapter to iterate just the values in a map?

前端 未结 4 1162
故里飘歌
故里飘歌 2020-12-01 16:17

I\'m just getting back into C++ after a couple of years of doing a lot of C#, and recently Objective C.

One thing I\'ve done before is to roll my own iterator adapte

4条回答
  •  误落风尘
    2020-12-01 17:10

    There is a boost range adaptor for exactly this purpose. See http://www.boost.org/doc/libs/1_53_0/libs/range/doc/html/range/reference/adaptors/reference/map_values.html

    (This example cribbed from there)

    int main(int argc, const char* argv[])
    {
        using namespace boost::assign;
        using namespace boost::adaptors;
    
        std::map input;
        for (int i = 0; i < 10; ++i)
        input.insert(std::make_pair(i, i * 10));
    
        boost::copy(
            input | map_values,
            std::ostream_iterator(std::cout, ","));
    
        return 0;
    }
    

提交回复
热议问题