【STL】list的构造函数

来源:互联网 发布:iphone录制视频软件 编辑:程序博客网 时间:2024/05/16 04:56
构造函数的声明:
  explicit list(     const Allocator& _Al  );  explicit list(     size_type _Count  );  list(     size_type _Count,     const Type& _Val  );  list(     size_type _Count,     const Type& _Val,     const Allocator& _Al  );  list(     const list& _Right  );  template<class InputIterator>     list(        InputIterator _First,        InputIterator _Last     );  template<class InputIterator >     list(        InputIterator _First,        InputIterator _Last,        const Allocator& _Al     );  list(     list&& _Right  );
例子:
// list的构造函数void test_list_constructor(){std::list<int>::iterator c4_Iter, c5_Iter;// 0. Create an empty list c0std::list<int> c0;// 1. Create a list c1 with 3 elements of default value 0std::list<int> c1(3);// 2. Create a list c2 with 5 elements of value 2std::list<int> c2(5, 2);// 3. Create a list c3 with 3 elements of value 1 and with the // allocator of list c2std::list<int> c3(3, 1, c2.get_allocator());// 4. Create a copy, list c4, of list c2std::list<int> c4(c2);// 5. Create a list c5 by copying the range c4[_First, _Last)c4_Iter = c4.begin();c4_Iter++;c4_Iter++;std::list<int> c5(c4.begin(), c4_Iter);// 6. Create a list c6 by copying the range c4[_First, _Last) and with // the allocator of list c2c4_Iter = c4.begin();c4_Iter++;c4_Iter++;c4_Iter++;std::list<int> c6(c4.begin(), c4_Iter, c2.get_allocator());std::cout << "c1 = ";std::copy(c1.begin(), c1.end(), std::ostream_iterator<int>(std::cout, " "));std::cout << std::endl;std::cout << "c2 = ";std::copy(c2.begin(), c2.end(), std::ostream_iterator<int>(std::cout, " "));std::cout << std::endl;std::cout << "c3 = ";std::copy(c3.begin(), c3.end(), std::ostream_iterator<int>(std::cout, " "));std::cout << std::endl;std::cout << "c4 = ";std::copy(c4.begin(), c4.end(), std::ostream_iterator<int>(std::cout, " "));std::cout << std::endl;std::cout << "c5 = ";std::copy(c5.begin(), c5.end(), std::ostream_iterator<int>(std::cout, " "));std::cout << std::endl;std::cout << "c6 = ";std::copy(c6.begin(), c6.end(), std::ostream_iterator<int>(std::cout, " "));std::cout << std::endl;}


原创粉丝点击