【STL】list的建構函式

來源:互聯網
上載者:User

建構函式的聲明:

  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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.