std::map::empty

来自cppreference.com

 
 
 
std::map
成员函数
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
map::map
map::~map
map::operator=
map::get_allocator
元素的访问
Original:
Element access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
map::at
map::operator[]
迭代器
Original:
Iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
map::begin
map::cbegin

(C++11)
map::end
map::cend

(C++11)
map::rbegin
map::crbegin

(C++11)
map::rend
map::crend

(C++11)
容量
Original:
Capacity
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
map::empty
map::size
map::max_size
修饰符
Original:
Modifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
map::clear
map::insert
map::emplace(C++11)
map::emplace_hint(C++11)
map::erase
map::swap
查找
Original:
Lookup
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
map::count
map::find
map::equal_range
map::lower_bound
map::upper_bound
观察员
Original:
Observers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
map::key_comp
map::value_comp
 
bool empty() const;
检查,如果容器有任何元素,即是否begin() == end().
Original:
Checks if the container has no elements, i.e. whether begin() == end().
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目录

[编辑] 参数

(无)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 返回值

true如果容器是空的,false其他方式
Original:
true if the container is empty, false otherwise
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 例外

noexcept specification:  
noexcept
  (C++11 起)

[编辑] 复杂性

常数
Original:
Constant
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 为例

下面的代码使用empty检查,如果std::map<int>包含任何元素
Original:
The following code uses empty to check if a std::map<int> contains any elements:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <map>
#include <iostream>
 
int main()
{
    std::map<int> numbers;
    std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n';
 
    numbers.push_back(42);
    numbers.push_back(13317);
    std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n';
}

Output:

Initially, numbers.empty(): 1
After adding elements, numbers.empty(): 0

See also

返回的元素数
Original:
returns the number of elements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共成员函数) [edit]