From 83729b83d02e76a1ac21ba5f420c4e925b5eac79 Mon Sep 17 00:00:00 2001 From: Brett <brettmaster1@gmail.com> Date: Sun, 4 Feb 2024 14:38:52 -0500 Subject: [PATCH] ugh TODO: measure gcc version --- include/blt/parse/obj_loader.h | 2 +- src/blt/parse/obj_loader.cpp | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/blt/parse/obj_loader.h b/include/blt/parse/obj_loader.h index c86e1bc..ea1d195 100644 --- a/include/blt/parse/obj_loader.h +++ b/include/blt/parse/obj_loader.h @@ -26,7 +26,7 @@ #include <string_view> #include <string> -namespace blt::gfx +namespace blt::parse { typedef blt::vec3f vertex_t; diff --git a/src/blt/parse/obj_loader.cpp b/src/blt/parse/obj_loader.cpp index 215dde3..a310d7b 100644 --- a/src/blt/parse/obj_loader.cpp +++ b/src/blt/parse/obj_loader.cpp @@ -27,8 +27,7 @@ #include "blt/std/utility.h" #include <blt/std/logging.h> - -namespace blt::gfx +namespace blt::parse { class char_tokenizer { @@ -59,7 +58,20 @@ namespace blt::gfx T get(std::string_view str) { T x; +#if __cplusplus >= BLT_CPP20 const auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), x); +#else + auto ec = std::errc(); + if constexpr (std::is_floating_point_v<T>) + { + x = static_cast<T>(std::stod(std::string(str))); + } else if constexpr (std::is_integral_v<T>) + { + x = static_cast<T>(std::stoll(std::string(str))); + } else + static_assert( + "You are using a c++ version which does not support the required std::from_chars, manual conversion has failed to find a type!"); +#endif // probably not needed. if (ec != std::errc()) {