Skip to content

std::stodの代わりにstd::from_charsを使用する#19

Merged
smdn merged 2 commits into
mainfrom
cpp-parse-number-with-from-chars
Jul 13, 2026
Merged

std::stodの代わりにstd::from_charsを使用する#19
smdn merged 2 commits into
mainfrom
cpp-parse-number-with-from-chars

Conversation

@smdn

@smdn smdn commented Jan 10, 2026

Copy link
Copy Markdown
Owner

Description

文字列から数値への変換において、std::stodの代わりにstd::from_charsを使用する。
これによって、例外ハンドリングの必要がない実装に簡略化する。

同時に、引数の型をstd::stringからstd::string_viewに変える。

ただし、GitHub Actions macOSランナーイメージのデフォルトのツールセットでは、まだstd::from_charsdoubleへの変換をサポートしていないようなので、サポートされ次第マージする。

Considerations

以下のように、まだstd::from_charsがサポートされていないので、デフォルトのツールセットでコンパイルできるようになるまでマージを控える。

Run tests with an implementation of C++ (GitHub Actions, make + G++) ...
Apple clang version 17.0.0 (clang-1700.0.13.5)
Target: arm64-apple-darwin24.6.0
Thread model: posix
InstalledDir: /Applications/Xcode_16.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
g++ -std=c++2a -O2 -Wall -c polish.cpp
polish.cpp:398:39: error: call to deleted function 'from_chars'
  398 |     [[maybe_unused]] auto [ptr, ec] = std::from_chars(
      |                                       ^~~~~~~~~~~~~~~
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__charconv/from_chars_integral.h:38:19: note: candidate function has been explicitly deleted
   38 | from_chars_result from_chars(const char*, const char*, bool, int = 10) = delete;
      |                   ^
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__charconv/from_chars_integral.h:224:1: note: candidate template ignored: requirement 'is_integral<double>::value' was not satisfied [with _Tp = double]
  224 | from_chars(const char* __first, const char* __last, _Tp& __value) {
      | ^
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__charconv/from_chars_integral.h:230:1: note: candidate function template not viable: requires 4 arguments, but 3 were provided
  230 | from_chars(const char* __first, const char* __last, _Tp& __value, int __base) {
      | ^          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [polish.o] Error 1
Run tests with an implementation of C++ (GitHub Actions, make + Clang) ...
Apple clang version 17.0.0 (clang-1700.0.13.5)
Target: arm64-apple-darwin24.6.0
Thread model: posix
InstalledDir: /Applications/Xcode_16.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
clang++ -std=c++2a -O2 -Wall -c polish.cpp
polish.cpp:398:39: error: call to deleted function 'from_chars'
  398 |     [[maybe_unused]] auto [ptr, ec] = std::from_chars(
      |                                       ^~~~~~~~~~~~~~~
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__charconv/from_chars_integral.h:38:19: note: candidate function has been explicitly deleted
   38 | from_chars_result from_chars(const char*, const char*, bool, int = 10) = delete;
      |                   ^
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__charconv/from_chars_integral.h:224:1: note: candidate template ignored: requirement 'is_integral<double>::value' was not satisfied [with _Tp = double]
  224 | from_chars(const char* __first, const char* __last, _Tp& __value) {
      | ^
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__charconv/from_chars_integral.h:230:1: note: candidate function template not viable: requires 4 arguments, but 3 were provided
  230 | from_chars(const char* __first, const char* __last, _Tp& __value, int __base) {
      | ^          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [polish.o] Error 1
Operating System
  macOS
  15.7.3
  24G419
Runner Image
  Image: macos-15-arm64
  Version: 20260105.0094.1
  Included Software: https://github.com/actions/runner-images/blob/macos-15-arm64/20260105.0094/images/macos/macos-15-arm64-Readme.md
  Image Release: https://github.com/actions/runner-images/releases/tag/macos-15-arm64%2F20260105.0094

@smdn
smdn marked this pull request as draft July 5, 2026 03:54
@smdn

smdn commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

macos-26 (macOS 26.4)でパスするようになったので、macos-latestとして展開され次第マージする。

@smdn
smdn marked this pull request as ready for review July 13, 2026 11:44
@smdn
smdn merged commit f219807 into main Jul 13, 2026
44 checks passed
@smdn
smdn deleted the cpp-parse-number-with-from-chars branch July 13, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant