edponce commented on code in PR #14827:
URL: https://github.com/apache/arrow/pull/14827#discussion_r1049002967


##########
cpp/src/arrow/util/reflection_internal.h:
##########
@@ -91,21 +92,260 @@ PropertyTuple<Properties...> MakeProperties(Properties... 
props) {
   return {std::make_tuple(props...)};
 }
 
+/// Returns a string_view containing the name of a value.
+template <auto>
+constexpr std::string_view nameof(bool include_leading_k = false);
+
+/// Returns a string_view containing the (unqualified) name of a type.
+template <typename>
+constexpr std::string_view nameof();
+
+/// Returns a string_view containing the name of an enumeration member.
+template <typename Enum>
+constexpr std::string_view enum_name(Enum e, bool include_leading_k = false);
+
+/// Returns the enumeration member corresponding to name, or
+/// nullopt if name doesn't correspond to an enum member.
 template <typename Enum>
-struct EnumTraits {};
+constexpr std::optional<Enum> enum_cast(std::string_view name);
+
+/// Returns the enumeration member corresponding to an integer, or
+/// nullopt if the integer doesn't correspond to an enum member.
+template <typename Enum, typename Int>
+constexpr auto enum_cast(Int i) -> 
std::optional<decltype(static_cast<Enum>(i))>;
+
+namespace impl {
+template <auto V>
+constexpr std::string_view pretty_function() {
+#ifdef _MSC_VER
+  return __FUNCSIG__;
+#else
+  return __PRETTY_FUNCTION__;
+#endif
+}
+
+template <typename T>
+constexpr std::string_view pretty_function() {
+#ifdef _MSC_VER
+  return __FUNCSIG__;
+#else
+  return __PRETTY_FUNCTION__;
+#endif
+}
+
+constexpr auto kValueNamePrefixSuffix = [] {
+  size_t prefix{}, suffix{};
+
+  auto raw = pretty_function<2234527>();
+  if (prefix = raw.find("2234527"); prefix != std::string_view::npos) {
+    suffix = raw.size() - prefix - std::string_view{"2234527"}.size();
+  } else {
+    // some compilers render hexadecimal integer template arguments
+    raw = pretty_function<0x346243>();
+    prefix = raw.find("0x346243");
+    suffix = raw.size() - prefix - std::string_view{"0x346243"}.size();
+  }
+
+  return std::pair{prefix, suffix};
+}();
+
+constexpr auto kTypeNamePrefixSuffix = [] {
+  auto raw = pretty_function<double>();
+  size_t prefix = raw.find("double");
+  size_t suffix = raw.size() - prefix - std::string_view{"double"}.size();
+  return std::pair{prefix, suffix};
+}();
+
+/// std::array is not constexpr in all STL impls
+template <typename T, size_t N>
+class array {
+ public:
+  constexpr array() = default;
 
-template <typename Enum, Enum... Values>
-struct BasicEnumTraits {
-  using CType = typename std::underlying_type<Enum>::type;
-  using Type = typename CTypeTraits<CType>::ArrowType;
-  static std::array<Enum, sizeof...(Values)> values() { return {Values...}; }
+  constexpr explicit array(const T* ptr) {
+    for (T& value : values_) {
+      value = *ptr++;
+    }
+  }
+
+  constexpr explicit array(const T (&arr)[N])  // NOLINT
+      : array{static_cast<const T*>(arr)} {}
+
+  [[nodiscard]] static constexpr size_t size() { return N; }
+  [[nodiscard]] constexpr const T* data() const { return values_; }
+  [[nodiscard]] constexpr T* data() { return values_; }
+  [[nodiscard]] constexpr const T* begin() const { return values_; }
+  [[nodiscard]] constexpr const T* end() const { return begin() + N; }
+  [[nodiscard]] constexpr const T& operator[](size_t i) const { return 
begin()[i]; }

Review Comment:
   why two different idioms for indexing?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to