| 
 | 
 
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(" AUSE"); 
    return EXIT_SUCCESS; 
} 
//! ccsdu2004 |   
 
 
 
 |