Skip to content

Commit

Permalink
Avoid use of C++17 constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashton Meuser authored and Ashton Meuser committed Jun 1, 2024
1 parent 3f19ac7 commit bd7fd8e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/string-container.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ Required because List does not support subscript operator, GDExtension PackedStr
#include "defs.h"

namespace {
template <typename, typename = void> struct has_subscript_operator: std::false_type {};
template <typename T> struct has_subscript_operator<T, std::void_t<decltype(std::declval<T&>()[std::declval<size_t>()])>>: std::true_type {};
template <typename, typename = void> struct has_subscript_operator: std::false_type {};
template <typename T> struct has_subscript_operator<T, std::void_t<decltype(std::declval<T&>()[std::declval<size_t>()])>>: std::true_type {};
template <typename, typename = void> struct has_get_method: std::false_type {};
template <typename T> struct has_get_method<T, std::void_t<decltype(std::declval<T&>().get(std::declval<size_t>()))>>: std::true_type {};
}

namespace godot{
template <typename T> String string_container_get(T container, const int i) {
if constexpr (has_subscript_operator<T>::value) return container[i];
else return container.get(i);
}
namespace godot {
template <typename T> typename std::enable_if<has_subscript_operator<T>::value, String>::type string_container_get(T container, const uint32_t i) {
return container[i];
}

template <typename T> typename std::enable_if<has_get_method<T>::value && !has_subscript_operator<T>::value, String>::type string_container_get(T container, const uint32_t i) {
return container.get(i);
}
}

#endif

0 comments on commit bd7fd8e

Please sign in to comment.