From 3d68799d9cc0039dd9f502a4b8ebbe4c1b049b7f Mon Sep 17 00:00:00 2001 From: Elliot <35050275+Apache-HB@users.noreply.github.com> Date: Tue, 30 Mar 2021 14:28:44 -0400 Subject: [PATCH] fix #162 (#163) * fix unreachable code warning when header is present * update macro name --- peglib.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/peglib.h b/peglib.h index 227468e..f42f689 100644 --- a/peglib.h +++ b/peglib.h @@ -13,6 +13,9 @@ #include #if __has_include() #include +#define CPPPEGLIB_HAS_CHARCONV true +#else +#define CPPPEGLIB_HAS_CHARCONV false #endif #include #include @@ -340,15 +343,13 @@ inline std::string resolve_escape_sequence(const char *s, size_t n) { template T token_to_number_(std::string_view sv) { T n = 0; -#if __has_include() - if constexpr (!std::is_floating_point::value) { + if constexpr (CPPPEGLIB_HAS_CHARCONV && !std::is_floating_point::value) { std::from_chars(sv.data(), sv.data() + sv.size(), n); - return n; + } else { + auto s = std::string(sv); + std::istringstream ss(s); + ss >> n; } -#endif - auto s = std::string(sv); - std::istringstream ss(s); - ss >> n; return n; }