Namespaces
Variants
Views
Actions

Difference between revisions of "Template:cpp/container/clear"

From cppreference.com
(explicit postcondition (size() returns zero))
(Explicitly mentions that all elements will be destroyed, which the standard says: http://eel.is/c++draft/container.requirements#sequence.reqmts-4.sentence-62)
Line 7: Line 7:
 
{{dcl end}}
 
{{dcl end}}
  
Removes all elements from the container. After this call, {{lc|size()}} returns zero.
+
Removes all elements from the container and destroys them. After this call, {{lc|size()}} returns zero.
  
 
Invalidates any references, pointers, or iterators referring to contained elements. {{#switch:{{{1|}}}|list|forward_list|map|multimap|set|multiset=Any past-the-end iterator remains valid.|vector|deque=Any past-the-end iterators are also invalidated.|unordered_map|unordered_multimap|unordered_set|unordered_multiset=May also invalidate past-the-end iterators.}}
 
Invalidates any references, pointers, or iterators referring to contained elements. {{#switch:{{{1|}}}|list|forward_list|map|multimap|set|multiset=Any past-the-end iterator remains valid.|vector|deque=Any past-the-end iterators are also invalidated.|unordered_map|unordered_multimap|unordered_set|unordered_multiset=May also invalidate past-the-end iterators.}}

Revision as of 13:29, 7 November 2018

void clear() noexcept;
(since {std})

Removes all elements from the container and destroys them. After this call, size() returns zero.

Invalidates any references, pointers, or iterators referring to contained elements.

Contents

Parameters

(none)

Return value

(none)

Complexity

Linear in the size of the container, i.e., the number of elements.



See also

erases elements
(public member function of std::{{{1}}}) [edit]