From eb1b575b1d9a9a4dd7e6d39e4647c182ed90f87d Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Sat, 30 Sep 2023 04:04:55 -0400 Subject: Unify conditional Constexprs to one file Add OVDL_STRING_CONSTEXPR Add OVDL_STR_OPT_CONSTEXPR --- include/openvic-dataloader/csv/LineObject.hpp | 8 +++---- include/openvic-dataloader/csv/ValueNode.hpp | 4 +++- include/openvic-dataloader/detail/Constexprs.hpp | 27 ++++++++++++++++++++++ .../detail/OptionalConstexpr.hpp | 9 -------- .../openvic-dataloader/detail/VectorConstexpr.hpp | 9 -------- .../v2script/AbstractSyntaxTree.hpp | 2 +- 6 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 include/openvic-dataloader/detail/Constexprs.hpp delete mode 100644 include/openvic-dataloader/detail/OptionalConstexpr.hpp delete mode 100644 include/openvic-dataloader/detail/VectorConstexpr.hpp (limited to 'include/openvic-dataloader') diff --git a/include/openvic-dataloader/csv/LineObject.hpp b/include/openvic-dataloader/csv/LineObject.hpp index b9ee9a5..99c79c6 100644 --- a/include/openvic-dataloader/csv/LineObject.hpp +++ b/include/openvic-dataloader/csv/LineObject.hpp @@ -14,7 +14,7 @@ #include #include -#include +#include namespace ovdl::csv { /// LineObject should be able to recognize the differences between: @@ -57,7 +57,7 @@ namespace ovdl::csv { /// Special Functionality /// Retrieves value, produces "" for empty values - constexpr std::string get_value_for(std::size_t position) const { + OVDL_STRING_CONSTEXPR std::string get_value_for(std::size_t position) const { if (position < _prefix_end || position >= _suffix_end) return ""; for (const auto& object : *this) { if (object.get_position() == position) return object.make(); @@ -65,7 +65,7 @@ namespace ovdl::csv { return ""; } /// Tries to retrieve string, produces nullopt for empty values - constexpr std::optional try_get_string_at(std::size_t position) const { + OVDL_STR_OPT_CONSTEXPR std::optional try_get_string_at(std::size_t position) const { if (position < _prefix_end || position >= _suffix_end) return std::nullopt; for (const auto& object : *this) { if (object.get_position() == position) return object.make(); @@ -89,7 +89,7 @@ namespace ovdl::csv { return ""; } /// Tries to retrieve string, produces nullopt for empty values - constexpr std::optional try_get_string_at(std::size_t position, const IsMap auto& map) const { + OVDL_STR_OPT_CONSTEXPR std::optional try_get_string_at(std::size_t position, const IsMap auto& map) const { if (position < _prefix_end || position >= _suffix_end) return std::nullopt; for (const auto& object : *this) { if (object.get_position() == position) return object.make_from_map(map); diff --git a/include/openvic-dataloader/csv/ValueNode.hpp b/include/openvic-dataloader/csv/ValueNode.hpp index e66dac0..786f218 100644 --- a/include/openvic-dataloader/csv/ValueNode.hpp +++ b/include/openvic-dataloader/csv/ValueNode.hpp @@ -10,6 +10,8 @@ #include #include +#include + #include #include #include @@ -54,7 +56,7 @@ namespace ovdl::csv { void add_to_list(internal_value_type value); bool list_is_empty() const; - inline std::string make_from_map(const IsMap auto& map) const { + OVDL_STRING_CONSTEXPR std::string make_from_map(const IsMap auto& map) const { std::vector pre_joined(_value_list.size()); for (auto&& value : _value_list) { diff --git a/include/openvic-dataloader/detail/Constexprs.hpp b/include/openvic-dataloader/detail/Constexprs.hpp new file mode 100644 index 0000000..ade1bfa --- /dev/null +++ b/include/openvic-dataloader/detail/Constexprs.hpp @@ -0,0 +1,27 @@ +#pragma once + +// THANK YOU APPLE FOR YOUR UTTER DISREGARD FOR C++20 + +#if defined(__cpp_lib_optional) && __cpp_lib_optional >= 202106L +#define OVDL_OPTIONAL_CONSTEXPR constexpr +#else +#define OVDL_OPTIONAL_CONSTEXPR inline +#endif + +#if defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L +#define OVDL_STRING_CONSTEXPR constexpr +#else +#define OVDL_STRING_CONSTEXPR inline +#endif + +#if defined(__cpp_lib_optional) && __cpp_lib_optional >= 202106L && defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L +#define OVDL_STR_OPT_CONSTEXPR constexpr +#else +#define OVDL_STR_OPT_CONSTEXPR inline +#endif + +#if defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L +#define OVDL_VECTOR_CONSTEXPR constexpr +#else +#define OVDL_VECTOR_CONSTEXPR inline +#endif \ No newline at end of file diff --git a/include/openvic-dataloader/detail/OptionalConstexpr.hpp b/include/openvic-dataloader/detail/OptionalConstexpr.hpp deleted file mode 100644 index bcb12a7..0000000 --- a/include/openvic-dataloader/detail/OptionalConstexpr.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -// THANK YOU APPLE FOR YOUR UTTER DISREGARD FOR C++20 - -#if __cpp_lib_optional >= 202106L -#define OVDL_OPTIONAL_CONSTEXPR constexpr -#else -#define OVDL_OPTIONAL_CONSTEXPR inline -#endif \ No newline at end of file diff --git a/include/openvic-dataloader/detail/VectorConstexpr.hpp b/include/openvic-dataloader/detail/VectorConstexpr.hpp deleted file mode 100644 index 7e7fa34..0000000 --- a/include/openvic-dataloader/detail/VectorConstexpr.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -// THANK YOU APPLE FOR YOUR UTTER DISREGARD FOR C++20 - -#if __cpp_lib_constexpr_vector >= 201907L -#define OVDL_VECTOR_CONSTEXPR constexpr -#else -#define OVDL_VECTOR_CONSTEXPR inline -#endif \ No newline at end of file diff --git a/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp b/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp index 8e39bd9..181a254 100644 --- a/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp +++ b/include/openvic-dataloader/v2script/AbstractSyntaxTree.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include -- cgit v1.2.3-56-ga3b1