最終更新日時(UTC):
が更新

履歴 編集

function
<span>

std::span::empty(C++20)

[[nodiscard]] constexpr bool empty() const noexcept;

概要

参照している範囲が空かどうかを判定する。

戻り値

以下と等価:

return size() == 0;

例外

投げない

計算量

定数時間

#include <cassert>
#include <span>
#include <vector>

int main()
{
  std::vector<int> v = {1, 2, 3, 4, 5};
  int* p = v.data();
  std::size_t n = 0;

  assert(!std::span{v}.empty());

  assert(std::span{v}.first(0).empty());
  assert((std::span<int>{p, n}.empty()));
}

出力

バージョン

言語

  • C++20

処理系