zoukankan      html  css  js  c++  java
  • Boost Bimap示例

    #include <string>
    #include <iostream>
    
    #include <boost/bimap.hpp>
    
    template< class MapType >
    void print_map(const MapType & map,
                   const std::string & separator,
                   std::ostream & os )
    {
        typedef typename MapType::const_iterator const_iterator;
    
        for( const_iterator i = map.begin(), iend = map.end(); i != iend; ++i )
        {
            os << i->first << separator << i->second << std::endl;
        }
    }
    
    int main()
    {
        // Soccer World cup
    
        typedef boost::bimap< std::string, int > results_bimap;
        typedef results_bimap::value_type position;
    
        results_bimap results;
        results.insert( position("Argentina"    ,1) );
        results.insert( position("Spain"        ,2) );
        results.insert( position("Germany"      ,3) );
        results.insert( position("France"       ,4) );
    
        std::cout << "The number of countries is " << results.size()
                  << std::endl;
    
        std::cout << "The winner is " << results.right.at(1)
                  << std::endl
                  << std::endl;
    
        std::cout << "Countries names ordered by their final position:"
                  << std::endl;
    
        // results.right works like a std::map< int, std::string >
    
        print_map( results.right, ") ", std::cout );
    
        std::cout << std::endl
                  << "Countries names ordered alphabetically along with"
                        "their final position:"
                  << std::endl;
    
        // results.left works like a std::map< std::string, int >
    
        print_map( results.left, " ends in position ", std::cout );
    
        return 0;
    }
  • 相关阅读:
    deque-size
    deque-size
    deque-resize
    Android4.4——SurfaceFlinger启动
    关于linux signal 6 (SIGABRT)
    (OK) 编译ANDROID
    compile android: depmod: ERROR: Found 2 modules in dependency cycles!
    Fedora 25正式发布:工作站版默认启用Wayland显示服务器
    running ANDROID
    (3/4 OK) 在VirtualBox中运行 cm-13-kiwi (华为 荣耀 5X)
  • 原文地址:https://www.cnblogs.com/chenkkkabc/p/3303644.html
Copyright © 2011-2022 走看看