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

履歴 編集

function
<span>

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

constexpr pointer data() const noexcept;

概要

参照範囲の先頭を指すポインタを取得する。

戻り値

メンバ変数として保持している、参照範囲の先頭を指すポインタを返す。

例外

投げない

計算量

定数時間

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

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

  int* p1 = std::span{v}.data();
  assert(p1 == &v[0]);

  int* p2 = std::span{v}.subspan(2, 3).data();
  assert(p2 == &v[2]);
}

出力

バージョン

言語

  • C++20

処理系