andishgar commented on code in PR #47586:
URL: https://github.com/apache/arrow/pull/47586#discussion_r2368853594
##########
cpp/src/arrow/tensor/converter.h:
##########
@@ -63,5 +66,55 @@ Result<std::shared_ptr<Tensor>>
MakeTensorFromSparseCSCMatrix(
Result<std::shared_ptr<Tensor>> MakeTensorFromSparseCSFTensor(
MemoryPool* pool, const SparseCSFTensor* sparse_tensor);
+template <typename Convertor>
+struct ConverterVisitor {
+ explicit ConverterVisitor(Convertor& converter) : converter(converter) {}
+ template <typename ValueType, typename IndexType>
+ Status operator()(const ValueType& value, const IndexType& index_type) {
+ return converter.Convert(value, index_type);
+ }
+
+ Convertor& converter;
+};
+
+struct ValueTypeVisitor {
+ template <typename ValueType, typename IndexType, typename Function>
+ enable_if_number<ValueType, Status> Visit(const ValueType& value_type,
+ const IndexType& index_type,
+ Function&& function) {
+ return function(value_type, index_type);
+ }
+
+ template <typename IndexType, typename Function>
+ Status Visit(const DataType& value_type, const IndexType&, Function&&) {
+ return Status::Invalid("Invalid value type and the type is ",
value_type.name());
+ }
+};
Review Comment:
Yes, for more details, see [the
documentation](https://arrow.apache.org/docs/dev/cpp/datatypes.html#visitor-pattern).
--
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]