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

履歴 編集

function
<optional>

std::optional::end(C++26)

constexpr iterator end() noexcept; // (1)
constexpr const_iterator end() const noexcept; // (2)

概要

optionalをrangeとした時の末尾要素の次を指すイテレータを取得する。

効果

begin() + has_value() を返す。

#include <iostream>
#include <iterator>
#include <optional>

int main()
{
  std::optional<int> p = 1;
  std::cout << std::distance(p.begin(), p.end()) << std::endl;

  p = std::null_opt;
  std::cout << std::distance(p.begin(), p.end()) << std::endl;
}

出力

1
0

バージョン

言語

  • C++26

処理系

参照