Remove charconv requirement (#142)

* Remove charconv requirement

It's the most restrictive compiler requirement (gcc 8.1, clang 7)

* Use has_include preprocessor function
pull/152/head
Nicholas Smith 3 years ago committed by GitHub
parent 6f73b76c5f
commit 15aa1380de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      peglib.h

@ -11,7 +11,9 @@
#include <any>
#include <cassert>
#include <cctype>
#if __has_include(<charconv>)
#include <charconv>
#endif
#include <cstring>
#include <functional>
#include <initializer_list>
@ -478,6 +480,7 @@ struct SemanticValues : protected std::vector<std::any> {
template <typename T> T token_to_number() const {
T n = 0;
#if __has_include(<charconv>)
if constexpr (std::is_floating_point<T>::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::any> {
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 <typename Annotation> struct AstBase : public Annotation {
template <typename T> T token_to_number() const {
T n = 0;
#if __has_include(<charconv>)
if constexpr (std::is_floating_point<T>::value) {
// TODO: The following code should be removed eventually.
std::istringstream ss(token_to_string());
@ -3780,6 +3789,11 @@ template <typename Annotation> 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
}
};

Loading…
Cancel
Save