Skip to content

Latest commit

 

History

History
56 lines (41 loc) · 822 Bytes

size.md

File metadata and controls

56 lines (41 loc) · 822 Bytes

size

  • span[meta header]
  • std[meta namespace]
  • span[meta class]
  • function[meta id-type]
  • cpp20[meta cpp]
constexpr index_type size() const noexcept;

概要

参照している要素数を取得する。

戻り値

メンバ変数として保持している要素数を返す。

例外

投げない

計算量

定数時間

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

int main()
{
  std::vector<int> v = {1, 2, 3, 4, 5};

  assert(std::span{v}.size() == 5);
  assert(std::span{v}.first(3).size() == 3);
}
  • size()[color ff0000]
  • first[link first.md]

出力

バージョン

言語

  • C++20

処理系