Namespaces
Variants
Views
Actions

Difference between revisions of "Template:cpp/container/size ad"

From cppreference.com
m () ⇒ c.size()|c.keys.size()
m (fmt.)
Line 15: Line 15:
 
{{dcl end}}
 
{{dcl end}}
  
Returns the number of elements in the container adaptor. Equivalent to {{#switch:{{#var:cont}}
+
Returns the number of elements in the container adaptor. Equivalent to: {{#switch:{{#var:cont}}
|flat_map|flat_multimap={{c|return c.keys.size()}}
+
|flat_map|flat_multimap=
|{{c|return c.size()}}
+
{{box|{{c/core|return}}{{nbspt}}{{rlpi|/#Member objects|c}}{{c/core|.keys.size()}}}}
 +
|<!--stack|queue|priority_queue=-->
 +
{{box|{{c/core|return}}{{nbspt}}{{rlpt|/#Member objects|c}}{{c/core|.size()}}}}
 
}}.
 
}}.
  
Line 34: Line 36:
 
|flat_set|flat_multiset={{include|cpp/container/set/example size|{{#var:cont}}}}
 
|flat_set|flat_multiset={{include|cpp/container/set/example size|{{#var:cont}}}}
 
|flat_map|flat_multimap={{include|cpp/container/map/example size|{{#var:cont}}}}
 
|flat_map|flat_multimap={{include|cpp/container/map/example size|{{#var:cont}}}}
|<!--stack, queue, priority_queue:-->
+
|<!--stack|queue|priority_queue=-->
 
{{example
 
{{example
 
|code=
 
|code=
#include <algorithm>
 
 
#include <cassert>
 
#include <cassert>
 
#include <{{#var:id}}>
 
#include <{{#var:id}}>

Revision as of 17:57, 1 November 2024

 
 
 
 
size_type size() const noexcept;
(since C++23)

Returns the number of elements in the container adaptor. Equivalent to: return c.keys.size().

Contents

Parameters

(none)

Return value

The number of elements in the container adaptor.

Complexity

Constant.

Example

#include <cassert>
#include <flat_map>
 
int main()
{
    std::flat_multimap<int, char> nums{{1, 'a'}, {1, 'b'}, {2, 'c'}, {2, 'd'}};
    assert(nums.size() == 4); 
}

See also

checks whether the container adaptor is empty
(public member function of std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>) [edit]
(C++17)(C++20)
returns the size of a container or array
(function template) [edit]
returns the maximum possible number of elements
(public member function of std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>) [edit]