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::optional::has_value - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. optional
  3. optional
  4. has_value

最終更新日時: 2026年09月11日 13時06分31秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<optional>

std::optional::has_value(C++17)

constexpr bool has_value() const noexcept;

概要

有効な値を保持しているかを判定する。

効果

有効値を保持している場合にtrueを返し、そうでなければfalseを返す。

例

#include <cassert>
#include <optional>

int main()
{
  std::optional<int> p1 = 3;
  assert(p1.has_value() == true);

  std::optional<int> p2;
  assert(p2.has_value() == false);
}

出力

バージョン

言語

  • C++17

処理系

  • Clang: 4.0.1 ✅
  • GCC: 7.2 ✅
  • Visual C++: ??

関連項目

  • optional::operator bool()
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.