游戏开发论坛

 找回密码
 立即注册
搜索
查看: 4615|回复: 0

boost之4.容器赋值操作

[复制链接]

56

主题

94

帖子

98

积分

注册会员

Rank: 2

积分
98
发表于 2010-8-14 20:48:00 | 显示全部楼层 |阅读模式
boost之4.容器赋值操作
这是使用Boost assigne小库的例子
包括map,vector,array的赋值操作
#include <cstdlib>
#include <iostream>
#include <boost/assign.hpp>
#include <boost/array.hpp>
#include <algorithm>
#include <iterator>
using
namespace std;
using
namespace boost;
using
namespace boost::assign;

int main(int argc, char
*argv[])
{
    //! vector赋值
    vector<int> v;
    v +=
1,2,3,4,5,6,7,8,9;
    copy(v.begin(),v.end(),ostream_iterator<int>(cout,"\n"));
   
    //! map
    map<string,int> m;
    insert(m)("foo",1)("bar",2)("ss",3);
    std::cout<<m.size()<<std::endl;
   
    //! boost array.
    typedef array<float,6> Array;
#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))   
    Array a = list_of(1.1)(2.2)(3.3)(4.4)(5.5)(6.6).to_array(a);
#else
    Array a = list_of(1.1)(2.2)(3.3)(4.4)(5.5)(6.6);
#endif
    copy(a.begin(),a.end(),ostream_iterator<float>(cout,"\n"));
   
    typedef boost::tuple<int,std::string,int> tuple;
    std::vector<tuple> vt = tuple_list_of(1,"foo",2)(3,"bar",4);
    std::map<std::string,int> mp = pair_list_of("foo",3)("bar",5);
   
    system(&quotAUSE");
    return EXIT_SUCCESS;
}
//! ccsdu2004
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2024-4-28 15:08

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表