Skip to content

Latest commit

 

History

History
60 lines (47 loc) · 1.08 KB

File metadata and controls

60 lines (47 loc) · 1.08 KB

operator bool

  • charconv[meta header]
  • std[meta namespace]
  • to_chars_result[meta class]
  • function[meta id-type]
  • cpp26[meta cpp]
constexpr explicit operator bool() const noexcept;

概要

変換が成功したかを判定する。

戻り値

return ec == errc{};
  • errc[link /reference/system_error/errc.md]

#include <iostream>
#include <charconv>
#include <string_view>

int main()
{
  char out[8]{};
  int value = 123;

  if (auto result = std::to_chars(std::begin(out), std::end(out), value)) {
    std::cout << std::string_view(out, result.ptr - out) << std::endl;
  }
  else {
    std::cout << "conversion failed" << std::endl;
  }
}
  • std::to_chars[link /reference/charconv/to_chars.md]

出力

123

バージョン

言語

  • C++26

処理系

参照