
- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ Array Library - empty() Function
Description
The C++ function std::array::empty() tests whether size of array is zero or not.
Declaration
Following is the declaration for std::array::empty() function form std::array header.
constexpr bool empty() noexcept;
Parameters
None
Return Value
Returns true if array size is 0 otherwise false.
Exceptions
This member function never throws exception.
Time complexity
Constant i.e. O(1)
Example
In below example size of arr1 is 0 that is why it will be treated as empty array and member function will return true value for arr1.
#include <iostream> #include <array> using namespace std; int main(void) { /* array size is zero, it will be treated as empty array */ array<int, 0> arr1; array<int, 10> arr2; if (arr1.empty()) cout << "arr1 is empty" << endl; else cout << "arr1 is not empty" << endl; if (arr2.empty()) cout << "arr2 is empty" << endl; else cout << "arr2 is not empty" << endl; }
Let us compile and run the above program, this will produce the following result −
arr1 is empty arr2 is not empty
array.htm
Advertisements