diff --git a/peglib.h b/peglib.h index b7c3164..ecf31d8 100644 --- a/peglib.h +++ b/peglib.h @@ -11,7 +11,9 @@ #include #include #include +#if __has_include() #include +#endif #include #include #include @@ -478,6 +480,7 @@ struct SemanticValues : protected std::vector { template T token_to_number() const { T n = 0; +#if __has_include() if constexpr (std::is_floating_point::value) { // TODO: The following code should be removed eventually. std::istringstream ss(token_to_string()); @@ -488,6 +491,11 @@ struct SemanticValues : protected std::vector { std::from_chars(sv.data(), sv.data() + sv.size(), n); return n; } +#else + std::istringstream ss(token_to_string()); + ss >> n; + return n; +#endif } // Transform the semantic value vector to another vector @@ -3770,6 +3778,7 @@ template struct AstBase : public Annotation { template T token_to_number() const { T n = 0; +#if __has_include() if constexpr (std::is_floating_point::value) { // TODO: The following code should be removed eventually. std::istringstream ss(token_to_string()); @@ -3780,6 +3789,11 @@ template struct AstBase : public Annotation { std::from_chars(token.data(), token.data() + token.size(), n); return n; } +#else + std::istringstream ss(token_to_string()); + ss >> n; + return n; +#endif } };