GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::array::empty - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. array
  3. array
  4. empty

最終更新日時: 2026年09月19日 21時31分51秒 (JST)
rotarymars が更新

履歴 編集

function
<array>

std::array::empty(C++11)

constexpr bool empty() noexcept;                     // C++11
constexpr bool empty() const noexcept;               // C++14
[[nodiscard]] constexpr bool empty() const noexcept; // C++20
constexpr bool empty() const noexcept;               // C++26

概要

コンテナが空かどうかを判定する

戻り値

コンテナが空であればtrue、そうでなければfalseを返す。

std::arrayコンテナに対して動的な要素の追加・削除はできないため、0要素を持つstd::array型オブジェクトを定義した場合にのみ、この関数はtrueを返す。

例外

投げない

計算量

定数時間

例

#include <iostream>
#include <array>

int main()
{
  std::array<int, 3> non_empty_array;
  std::array<int, 0> empty_array;

  std::cout << std::boolalpha;
  std::cout << "non_empty_array : " << non_empty_array.empty() << std::endl;
  std::cout << "empty_array : " << empty_array.empty() << std::endl;
}

出力

non_empty_array : false
empty_array : true

バージョン

言語

  • C++11

処理系

  • Clang: 9.0.1 ✅
  • GCC: 4.7.0 ✅
  • Visual C++: 2008 (std::tr1) ✅, 2010 ✅, 2012 ✅

参照

  • N3669 Fixing constexpr member functions without const
  • P0600R1 [[nodiscard]] in the Library
    • C++20で[[nodiscard]]が付加された
  • P2422R1 Remove nodiscard annotations from the standard library specification
    • C++26で[[nodiscard]]指定が削除された
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.