You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "taepper (via GitHub)" <gi...@apache.org> on 2026/09/14 13:43:13 UTC
[PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
taepper opened a new pull request, #51328:
URL: https://github.com/apache/arrow/pull/51328
### Rationale for this change
This is the last change for #50250. The remaining `FnOnce` does not have corresponding utilities in the C++20 standard library according to my knowledge.
### What changes are included in this PR?
This removes the custom meta-programming facility `call_traits::argument_type`. We instead use the provided `type_traits` header which allows us to check invocability (and thus indirectly the argument type) with e.g. `std::is_invocable`.
It needs to be mentioned that none of `std::is_invocable_v`, `std::invoke_result_t`, .. is a drop-in replacement for the removed `argument_type`. I instead migrated all users of the old facility to the standard constructs. Some call-sites needed changing by supplying template parameters explicitly, but in my opinion all changes are defendable or even improvements.
### Are these changes tested?
Yes, this refactoring commit still passes all test cases
### Are there any user-facing changes?
No
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #51328:
URL: https://github.com/apache/arrow/pull/51328#discussion_r4023649213
##########
cpp/src/arrow/util/cache_internal.h:
##########
@@ -167,42 +166,42 @@ struct ThreadUnsafeMemoizer {
};
template <template <typename...> class Cache, template <typename...> class MemoizerType,
- typename Func, typename Key = std::decay_t<call_traits::argument_type<0, Func>>,
- typename Value = std::decay_t<std::invoke_result_t<Func, const Key&>>,
- typename Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>,
- typename RetType = typename Memoizer::RetType>
-static std::function<RetType(const Key&)> Memoize(Func&& func, int32_t cache_capacity) {
+ typename Key, typename Func>
+static auto Memoize(Func&& func, int32_t cache_capacity) {
+ using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
+ using Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>;
+ using RetType = typename Memoizer::RetType;
+
// std::function<> requires copy constructibility
struct {
RetType operator()(const Key& key) const { return (*memoized_)(key); }
std::shared_ptr<Memoizer> memoized_;
} shared_memoized = {
std::make_shared<Memoizer>(std::forward<Func>(func), cache_capacity)};
- return shared_memoized;
+ return std::function<RetType(const Key&)>(std::move(shared_memoized));
Review Comment:
I previously copied and modified this file in iceberg-cpp repo; it might be what pitrou says. Maybe we can open a new PR to refactor the code. https://github.com/apache/iceberg-cpp/pull/891/changes#diff-6e67f7ceb80cef4c07b66e68bc6907d481231abde46ce1168ed492eadbceb6f1
However, I discovered that no code within Arrow currently uses this `arrow::internal::LruCache`; perhaps we can simply delete the file.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
Posted by "taepper (via GitHub)" <gi...@apache.org>.
taepper commented on code in PR #51328:
URL: https://github.com/apache/arrow/pull/51328#discussion_r4009369884
##########
cpp/src/arrow/util/cache_internal.h:
##########
@@ -167,42 +166,42 @@ struct ThreadUnsafeMemoizer {
};
template <template <typename...> class Cache, template <typename...> class MemoizerType,
- typename Func, typename Key = std::decay_t<call_traits::argument_type<0, Func>>,
- typename Value = std::decay_t<std::invoke_result_t<Func, const Key&>>,
- typename Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>,
- typename RetType = typename Memoizer::RetType>
-static std::function<RetType(const Key&)> Memoize(Func&& func, int32_t cache_capacity) {
+ typename Key, typename Func>
+static auto Memoize(Func&& func, int32_t cache_capacity) {
+ using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
+ using Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>;
+ using RetType = typename Memoizer::RetType;
+
// std::function<> requires copy constructibility
struct {
RetType operator()(const Key& key) const { return (*memoized_)(key); }
std::shared_ptr<Memoizer> memoized_;
} shared_memoized = {
std::make_shared<Memoizer>(std::forward<Func>(func), cache_capacity)};
- return shared_memoized;
+ return std::function<RetType(const Key&)>(std::move(shared_memoized));
Review Comment:
Maybe I am understanding the code wrong, but I thought the change is equivalent.
The previous version had the function declaration:
`static std::function<RetType(const Key&)> Memoize(...)`
whereas now we have
`static auto Memoize(...)`
so all I did in the return statement was changing the _implicit_ conversion to a `std::function` to an explicit one
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou merged PR #51328:
URL: https://github.com/apache/arrow/pull/51328
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #51328:
URL: https://github.com/apache/arrow/pull/51328#discussion_r4023649213
##########
cpp/src/arrow/util/cache_internal.h:
##########
@@ -167,42 +166,42 @@ struct ThreadUnsafeMemoizer {
};
template <template <typename...> class Cache, template <typename...> class MemoizerType,
- typename Func, typename Key = std::decay_t<call_traits::argument_type<0, Func>>,
- typename Value = std::decay_t<std::invoke_result_t<Func, const Key&>>,
- typename Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>,
- typename RetType = typename Memoizer::RetType>
-static std::function<RetType(const Key&)> Memoize(Func&& func, int32_t cache_capacity) {
+ typename Key, typename Func>
+static auto Memoize(Func&& func, int32_t cache_capacity) {
+ using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
+ using Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>;
+ using RetType = typename Memoizer::RetType;
+
// std::function<> requires copy constructibility
struct {
RetType operator()(const Key& key) const { return (*memoized_)(key); }
std::shared_ptr<Memoizer> memoized_;
} shared_memoized = {
std::make_shared<Memoizer>(std::forward<Func>(func), cache_capacity)};
- return shared_memoized;
+ return std::function<RetType(const Key&)>(std::move(shared_memoized));
Review Comment:
I previously copied and modified this file in iceberg-cpp repo; it might be as pitrou described. Maybe we can open a new PR to refactor the code. https://github.com/apache/iceberg-cpp/pull/891/changes#diff-6e67f7ceb80cef4c07b66e68bc6907d481231abde46ce1168ed492eadbceb6f1
However, I discovered that no code within Arrow currently uses this `arrow::internal::LruCache`; perhaps we can simply delete the file.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #51328:
URL: https://github.com/apache/arrow/pull/51328#discussion_r4023649213
##########
cpp/src/arrow/util/cache_internal.h:
##########
@@ -167,42 +166,42 @@ struct ThreadUnsafeMemoizer {
};
template <template <typename...> class Cache, template <typename...> class MemoizerType,
- typename Func, typename Key = std::decay_t<call_traits::argument_type<0, Func>>,
- typename Value = std::decay_t<std::invoke_result_t<Func, const Key&>>,
- typename Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>,
- typename RetType = typename Memoizer::RetType>
-static std::function<RetType(const Key&)> Memoize(Func&& func, int32_t cache_capacity) {
+ typename Key, typename Func>
+static auto Memoize(Func&& func, int32_t cache_capacity) {
+ using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
+ using Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>;
+ using RetType = typename Memoizer::RetType;
+
// std::function<> requires copy constructibility
struct {
RetType operator()(const Key& key) const { return (*memoized_)(key); }
std::shared_ptr<Memoizer> memoized_;
} shared_memoized = {
std::make_shared<Memoizer>(std::forward<Func>(func), cache_capacity)};
- return shared_memoized;
+ return std::function<RetType(const Key&)>(std::move(shared_memoized));
Review Comment:
I previously copied and modified this file in iceberg-cpp repo. The file in iceberg-cpp might be as pitrou described. Maybe we can open a new PR to refactor the code. https://github.com/apache/iceberg-cpp/pull/891/changes#diff-6e67f7ceb80cef4c07b66e68bc6907d481231abde46ce1168ed492eadbceb6f1
```cpp
template <template <typename...> class MemoizerType, typename Func>
auto Memoize(Func&& func, int32_t cache_capacity) {
using Function = decltype(std::function{std::forward<Func>(func)});
using Key = std::decay_t<typename unary_traits<Function>::arg>;
using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
using Memoizer = MemoizerType<Key, Value, LruCache<Key, Value>, Func>;
return Memoizer(std::forward<Func>(func), cache_capacity);
}
// Apply a LRU memoization cache to a callable.
template <typename Func>
auto MemoizeLru(Func&& func, int32_t cache_capacity) {
return Memoize<ThreadSafeMemoizer>(std::forward<Func>(func), cache_capacity);
}
```
However, I discovered that no code within Arrow currently uses this `arrow::internal::LruCache`; perhaps we can simply delete the file.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #51328:
URL: https://github.com/apache/arrow/pull/51328#discussion_r4027861697
##########
cpp/src/arrow/util/cache_internal.h:
##########
@@ -167,42 +166,42 @@ struct ThreadUnsafeMemoizer {
};
template <template <typename...> class Cache, template <typename...> class MemoizerType,
- typename Func, typename Key = std::decay_t<call_traits::argument_type<0, Func>>,
- typename Value = std::decay_t<std::invoke_result_t<Func, const Key&>>,
- typename Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>,
- typename RetType = typename Memoizer::RetType>
-static std::function<RetType(const Key&)> Memoize(Func&& func, int32_t cache_capacity) {
+ typename Key, typename Func>
+static auto Memoize(Func&& func, int32_t cache_capacity) {
+ using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
+ using Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>;
+ using RetType = typename Memoizer::RetType;
+
// std::function<> requires copy constructibility
struct {
RetType operator()(const Key& key) const { return (*memoized_)(key); }
std::shared_ptr<Memoizer> memoized_;
} shared_memoized = {
std::make_shared<Memoizer>(std::forward<Func>(func), cache_capacity)};
- return shared_memoized;
+ return std::function<RetType(const Key&)>(std::move(shared_memoized));
Review Comment:
> However, I discovered that no code within Arrow currently uses this `arrow::internal::LruCache`; perhaps we can simply delete the file.
Let's open a separate issue for that?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #51328:
URL: https://github.com/apache/arrow/pull/51328#discussion_r4006553808
##########
cpp/src/arrow/util/cache_internal.h:
##########
@@ -167,42 +166,42 @@ struct ThreadUnsafeMemoizer {
};
template <template <typename...> class Cache, template <typename...> class MemoizerType,
- typename Func, typename Key = std::decay_t<call_traits::argument_type<0, Func>>,
- typename Value = std::decay_t<std::invoke_result_t<Func, const Key&>>,
- typename Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>,
- typename RetType = typename Memoizer::RetType>
-static std::function<RetType(const Key&)> Memoize(Func&& func, int32_t cache_capacity) {
+ typename Key, typename Func>
+static auto Memoize(Func&& func, int32_t cache_capacity) {
+ using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
+ using Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>;
+ using RetType = typename Memoizer::RetType;
+
// std::function<> requires copy constructibility
struct {
RetType operator()(const Key& key) const { return (*memoized_)(key); }
std::shared_ptr<Memoizer> memoized_;
} shared_memoized = {
std::make_shared<Memoizer>(std::forward<Func>(func), cache_capacity)};
- return shared_memoized;
+ return std::function<RetType(const Key&)>(std::move(shared_memoized));
Review Comment:
Wrapping the result in a `std::function` adds a layer of indirection when calling `operator()` that might be expensive. Can we avoid this?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #51328:
URL: https://github.com/apache/arrow/pull/51328#issuecomment-5666127263
Unfortunately we'll have to wait for https://github.com/apache/arrow/pull/51326 before we can ensure that this doesn't break on some C++ compilers on our CI platforms.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #51328:
URL: https://github.com/apache/arrow/pull/51328#discussion_r4023649213
##########
cpp/src/arrow/util/cache_internal.h:
##########
@@ -167,42 +166,42 @@ struct ThreadUnsafeMemoizer {
};
template <template <typename...> class Cache, template <typename...> class MemoizerType,
- typename Func, typename Key = std::decay_t<call_traits::argument_type<0, Func>>,
- typename Value = std::decay_t<std::invoke_result_t<Func, const Key&>>,
- typename Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>,
- typename RetType = typename Memoizer::RetType>
-static std::function<RetType(const Key&)> Memoize(Func&& func, int32_t cache_capacity) {
+ typename Key, typename Func>
+static auto Memoize(Func&& func, int32_t cache_capacity) {
+ using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
+ using Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>;
+ using RetType = typename Memoizer::RetType;
+
// std::function<> requires copy constructibility
struct {
RetType operator()(const Key& key) const { return (*memoized_)(key); }
std::shared_ptr<Memoizer> memoized_;
} shared_memoized = {
std::make_shared<Memoizer>(std::forward<Func>(func), cache_capacity)};
- return shared_memoized;
+ return std::function<RetType(const Key&)>(std::move(shared_memoized));
Review Comment:
I previously modified this file in iceberg-cpp repo; it might be similar to what pitrou is looking for. Maybe we can open a new PR to refactor the code. https://github.com/apache/iceberg-cpp/pull/891/changes#diff-6e67f7ceb80cef4c07b66e68bc6907d481231abde46ce1168ed492eadbceb6f1
However, I discovered that no code within Arrow currently uses this `arrow::internal::LruCache`; perhaps we can simply delete the file.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #51328:
URL: https://github.com/apache/arrow/pull/51328#issuecomment-5700254100
I've rebased and hopefully we can get mostly green CI.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #51328:
URL: https://github.com/apache/arrow/pull/51328#discussion_r4027855568
##########
cpp/src/arrow/util/cache_internal.h:
##########
@@ -167,42 +166,42 @@ struct ThreadUnsafeMemoizer {
};
template <template <typename...> class Cache, template <typename...> class MemoizerType,
- typename Func, typename Key = std::decay_t<call_traits::argument_type<0, Func>>,
- typename Value = std::decay_t<std::invoke_result_t<Func, const Key&>>,
- typename Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>,
- typename RetType = typename Memoizer::RetType>
-static std::function<RetType(const Key&)> Memoize(Func&& func, int32_t cache_capacity) {
+ typename Key, typename Func>
+static auto Memoize(Func&& func, int32_t cache_capacity) {
+ using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
+ using Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>;
+ using RetType = typename Memoizer::RetType;
+
// std::function<> requires copy constructibility
struct {
RetType operator()(const Key& key) const { return (*memoized_)(key); }
std::shared_ptr<Memoizer> memoized_;
} shared_memoized = {
std::make_shared<Memoizer>(std::forward<Func>(func), cache_capacity)};
- return shared_memoized;
+ return std::function<RetType(const Key&)>(std::move(shared_memoized));
Review Comment:
> The previous version had the function declaration:
> `static std::function<RetType(const Key&)> Memoize(...)`
Oh, you're right, I misread. Sorry for the noise!
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #51328:
URL: https://github.com/apache/arrow/pull/51328#discussion_r4023649213
##########
cpp/src/arrow/util/cache_internal.h:
##########
@@ -167,42 +166,42 @@ struct ThreadUnsafeMemoizer {
};
template <template <typename...> class Cache, template <typename...> class MemoizerType,
- typename Func, typename Key = std::decay_t<call_traits::argument_type<0, Func>>,
- typename Value = std::decay_t<std::invoke_result_t<Func, const Key&>>,
- typename Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>,
- typename RetType = typename Memoizer::RetType>
-static std::function<RetType(const Key&)> Memoize(Func&& func, int32_t cache_capacity) {
+ typename Key, typename Func>
+static auto Memoize(Func&& func, int32_t cache_capacity) {
+ using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
+ using Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>;
+ using RetType = typename Memoizer::RetType;
+
// std::function<> requires copy constructibility
struct {
RetType operator()(const Key& key) const { return (*memoized_)(key); }
std::shared_ptr<Memoizer> memoized_;
} shared_memoized = {
std::make_shared<Memoizer>(std::forward<Func>(func), cache_capacity)};
- return shared_memoized;
+ return std::function<RetType(const Key&)>(std::move(shared_memoized));
Review Comment:
I previously copied and modified this file in iceberg-cpp repo. The file in iceberg-cpp might be as pitrou described. Maybe we can open a new PR to refactor the code. https://github.com/apache/iceberg-cpp/pull/891/changes#diff-6e67f7ceb80cef4c07b66e68bc6907d481231abde46ce1168ed492eadbceb6f1
However, I discovered that no code within Arrow currently uses this `arrow::internal::LruCache`; perhaps we can simply delete the file.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50250: [C++] Remove `call_traits::argument_type` in favor of `` [arrow]
Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #51328:
URL: https://github.com/apache/arrow/pull/51328#discussion_r4023649213
##########
cpp/src/arrow/util/cache_internal.h:
##########
@@ -167,42 +166,42 @@ struct ThreadUnsafeMemoizer {
};
template <template <typename...> class Cache, template <typename...> class MemoizerType,
- typename Func, typename Key = std::decay_t<call_traits::argument_type<0, Func>>,
- typename Value = std::decay_t<std::invoke_result_t<Func, const Key&>>,
- typename Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>,
- typename RetType = typename Memoizer::RetType>
-static std::function<RetType(const Key&)> Memoize(Func&& func, int32_t cache_capacity) {
+ typename Key, typename Func>
+static auto Memoize(Func&& func, int32_t cache_capacity) {
+ using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
+ using Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>;
+ using RetType = typename Memoizer::RetType;
+
// std::function<> requires copy constructibility
struct {
RetType operator()(const Key& key) const { return (*memoized_)(key); }
std::shared_ptr<Memoizer> memoized_;
} shared_memoized = {
std::make_shared<Memoizer>(std::forward<Func>(func), cache_capacity)};
- return shared_memoized;
+ return std::function<RetType(const Key&)>(std::move(shared_memoized));
Review Comment:
I previously copied and modified this file in iceberg-cpp repo; it might be similar to what pitrou is looking for. Maybe we can open a new PR to refactor the code. https://github.com/apache/iceberg-cpp/pull/891/changes#diff-6e67f7ceb80cef4c07b66e68bc6907d481231abde46ce1168ed492eadbceb6f1
However, I discovered that no code within Arrow currently uses this `arrow::internal::LruCache`; perhaps we can simply delete the file.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org