std::forward_list<T,Allocator>::empty
來自 cppreference.com
< cpp | 容器 | forward_list
bool empty() const noexcept; |
(C++11 起) | |
檢查容器是否不包含任何元素,即 begin() == end() 是否成立。
目錄 |
[編輯] 返回值
如果容器為空,則為 true;否則為 false。
[編輯] 複雜度
常數時間。
[編輯] 示例
以下程式碼使用 empty
檢查 std::forward_list<int> 是否包含任何元素。
執行此程式碼
#include <forward_list> #include <iostream> int main() { std::forward_list<int> numbers; std::cout << std::boolalpha; std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n'; numbers.push_front(42); numbers.push_front(13317); std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n'; }
輸出
Initially, numbers.empty(): true After adding elements, numbers.empty(): false
[編輯] 參閱
返回兩個迭代器間的距離 (函式模板) |