pitrou commented on code in PR #39937:
URL: https://github.com/apache/arrow/pull/39937#discussion_r1478443626


##########
cpp/src/arrow/datum.cc:
##########
@@ -73,86 +74,108 @@ std::shared_ptr<Array> Datum::make_array() const {
 }
 
 const std::shared_ptr<DataType>& Datum::type() const {
-  if (this->kind() == Datum::ARRAY) {
-    return std::get<std::shared_ptr<ArrayData>>(this->value)->type;
-  }
-  if (this->kind() == Datum::CHUNKED_ARRAY) {
-    return std::get<std::shared_ptr<ChunkedArray>>(this->value)->type();
-  }
-  if (this->kind() == Datum::SCALAR) {
-    return std::get<std::shared_ptr<Scalar>>(this->value)->type;
-  }
-  static std::shared_ptr<DataType> no_type;
-  return no_type;
+  return std::visit(
+      [](const auto& value) -> const std::shared_ptr<DataType>& {
+        using T = std::decay_t<decltype(value)>;
+
+        if constexpr (std::is_same_v<T, std::shared_ptr<Scalar>> ||
+                      std::is_same_v<T, std::shared_ptr<ArrayData>>) {
+          return value->type;
+        } else if constexpr (std::is_same_v<T, std::shared_ptr<ChunkedArray>>) 
{
+          return value->type();
+        } else {
+          static std::shared_ptr<DataType> no_type;
+          return no_type;

Review Comment:
   Ah, sorry, I had forgotten about the reference part. Then the current code 
looks ok to me. No need to add an abstraction IMHO :-)



-- 
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