C++ åèæå
- C++11
- C++14
- C++17
- C++20
- C++ ç¼è¯å¨æ¯ææ åµè¡¨
- ç¬ç«ä¸å®¿ä¸»å®ç°
- C++ è¯è¨
- C++ å ³é®è¯
- é¢å¤çå¨
- C++ æ ååºå¤´æä»¶
- å ·åè¦æ±
- åè½ç¹æ§æµè¯ (C++20)
- å·¥å ·åº
- ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼
- æ¦å¿µåº (C++20)
- é误å¤ç
- 卿å å管ç
- æ¥æåæ¶é´å·¥å ·
- å符串åº
- 容å¨åº
- std::array
- std::vector
- std::map
- std::unordered_map
- std::priority_queue
- std::span
- std::forward_list
- std::deque
- std::list
- std::list<T,Allocator>::list
- std::list<T,Allocator>::~list
- std::list<T,Allocator>::operator=
- std::list<T,Allocator>::unique
- std::list<T,Allocator>::empty
- std::set
- std::multiset
- std::multimap
- std::unordered_set
- std::unordered_multiset
- std::unordered_multimap
- std::stack
- std::queue
- std::vector<bool>
- ç»ç¹ææ (C++17)
- 注é
- è¿ä»£å¨åº
- èå´åº (C++20)
- ç®æ³åº
- æ°å¼åº
- è¾å ¥/è¾åºåº
- æä»¶ç³»ç»åº
- æ¬å°ååº
- æ£å表达å¼åº
- ååæä½åº
- çº¿ç¨æ¯æåº
- å®éªæ§ C++ ç¹æ§
- æç¨çèµæº
- ç´¢å¼
- std 符å·ç´¢å¼
- åç¨æ¯æ (C++20)
- C++ å ³é®è¯
ä½ç½®ï¼é¦é¡µ > C++ åèæå >容å¨åº >std::list > std::list<T,Allocator>::list
std::list<T,Allocator>::list
| list(); |
(1) | |
| explicit list( const Allocator& alloc ); |
(2) | |
| (3) | ||
| explicit list( size_type count, Â Â Â Â Â Â Â Â const T& value = T(), |
(C++11 å) | |
| Â Â Â Â Â Â Â Â Â list( size_type count, Â Â Â Â Â Â Â Â const T& value, |
(C++11 èµ·) | |
| (4) | ||
| explicit list( size_type count ); |
(C++11 èµ·) (C++14 å) |
|
| explicit list( size_type count, const Allocator& alloc = Allocator() ); |
(C++14 èµ·) | |
| template< class InputIt > list( InputIt first, InputIt last, |
(5) | |
| list( const list& other ); |
(6) | |
| list( const list& other, const Allocator& alloc ); |
(6) | (C++11 èµ·) |
| list( list&& other ); |
(7) | (C++11 èµ·) |
| list( list&& other, const Allocator& alloc ); |
(8) | (C++11 èµ·) |
| list( std::initializer_list<T> init, Â Â Â const Allocator& alloc = Allocator() ); |
(9) | (C++11 èµ·) |
ä»åç§æ°æ®æºæé æ°å®¹å¨ï¼å¯éå°ä½¿ç¨ç¨æ·æä¾çåé
å¨ alloc ã
alloc ç空容å¨ãcount 个æå¼ value çå
ç´ ç容å¨ã[first, last) å
容ç容å¨ã
|
è¥ |
(C++11 å) |
|
æ¤éè½½ä»
è¥ |
(C++11 èµ·) |
other å
容ç容å¨ãè¥ä¸æä¾ alloc ï¼åå¦åéè¿è°ç¨ std::allocator_traits<allocator_type>::select_on_container_copy_construction(other.get_allocator()) è·å¾åé
å¨ãother å
容ç容å¨ãåé
å¨éè¿å±äº other çåé
å¨ç§»å¨æé è·å¾ãalloc 为æ°å®¹å¨çåé
å¨ï¼ä» other ç§»å¨å
容ï¼è¥ alloc != other.get_allocator() ï¼åå®å¯¼è´éå
ç´ ç§»å¨ãinit å
容ç容å¨ãåæ°
| alloc | - | ç¨äºæ¤å®¹å¨ææå ååé çåé å¨ |
| count | - | 容å¨çå¤§å° |
| value | - | 以ä¹åå§å容å¨å ç´ çå¼ |
| first, last | - | å¤å¶å ç´ çæ¥æºèå´ |
| other | - | ç¨ä½åå§å容å¨å ç´ æ¥æºçå¦ä¸å®¹å¨ |
| init | - | ç¨ä½åå§åå ç´ æ¥æºç initializer_list |
å¤æåº¦
count æçº¿æ§first å last çè·ç¦»æçº¿æ§other çå¤§å°æçº¿æ§init çå¤§å°æçº¿æ§ãå¼å¸¸
å° Allocator::allocate çè°ç¨å¯è½æåºã
注æ
å¨å®¹å¨ç§»å¨æé ï¼éè½½ (7) ï¼åï¼æå other çå¼ç¨åè¿ä»£å¨ï¼é¤äºå°¾è¿ä»£å¨ï¼ä¿æåæ³ï¼ä½æä»£ç°äº *this ä¸çå
ç´ ãå½åæ åç± [container.requirements.general]/12 ä¸çæ»æ¬éè¿°ä½åºæ¤ä¿è¯ï¼è LWG 2321 æ£å¨èèæ´ä¸¥æ ¼çä¿è¯ã
示ä¾
#include <list> #include <string> #include <iostream>  template<typename T> std::ostream& operator<<(std::ostream& s, const std::list<T>& v) { s.put('['); char comma[3] = {'\0', ' ', '\0'}; for (const auto& e : v) { s << comma << e; comma[0] = ','; } return s << ']'; }  int main() { // c++11 åå§åå¨åè¡¨è¯æ³ï¼ std::list<std::string> words1 {"the", "frogurt", "is", "also", "cursed"}; std::cout << "words1: " << words1 << '\n';  // words2 == words1 std::list<std::string> words2(words1.begin(), words1.end()); std::cout << "words2: " << words2 << '\n';  // words3 == words1 std::list<std::string> words3(words1); std::cout << "words3: " << words3 << '\n';  // words4 为 {"Mo", "Mo", "Mo", "Mo", "Mo"} std::list<std::string> words4(5, "Mo"); std::cout << "words4: " << words4 << '\n'; }
è¾åºï¼
words1: [the, frogurt, is, also, cursed] words2: [the, frogurt, is, also, cursed] words3: [the, frogurt, is, also, cursed] words4: [Mo, Mo, Mo, Mo, Mo]
ç¼ºé·æ¥å
ä¸åæ´æ¹è¡ä¸ºçç¼ºé·æ¥å追溯å°åºç¨äºä»¥ååºçç C++ æ åã
| DR | åºç¨äº | åºçæ¶çè¡ä¸º | æ£ç¡®è¡ä¸º |
|---|---|---|---|
| LWG 2193 | C++11 | é»è®¤æé 彿°ä¸º explicit | 使ä¹ä¸ºé explicit |
åé
| å°å¼èµç»å®¹å¨ (å ¬å¼æå彿°) | |
| èµå¼ç»å®¹å¨ (å ¬å¼æå彿°) |