|
22 | 22 | #include <functional> |
23 | 23 | #include <memory> |
24 | 24 | #include <tuple> |
| 25 | +#include <type_traits> |
25 | 26 | #include <utility> |
26 | 27 | #include <vector> |
27 | 28 |
|
@@ -200,10 +201,10 @@ class NullaryFunctionAdapter |
200 | 201 | return std::make_unique<UnaryFunctionImpl>(std::move(fn)); |
201 | 202 | } |
202 | 203 |
|
203 | | - static std::unique_ptr<cel::Function> WrapFunction( |
204 | | - absl::AnyInvocable<T() const> function) { |
| 204 | + template <typename F, typename = std::enable_if_t<std::is_invocable_v<F>>> |
| 205 | + static std::unique_ptr<cel::Function> WrapFunction(F&& function) { |
205 | 206 | return WrapFunction( |
206 | | - [function = std::move(function)]( |
| 207 | + [function = std::forward<F>(function)]( |
207 | 208 | const google::protobuf::DescriptorPool* absl_nonnull, |
208 | 209 | google::protobuf::MessageFactory* absl_nonnull, |
209 | 210 | google::protobuf::Arena* absl_nonnull) -> T { return function(); }); |
@@ -276,10 +277,10 @@ class UnaryFunctionAdapter : public RegisterHelper<UnaryFunctionAdapter<T, U>> { |
276 | 277 | return std::make_unique<UnaryFunctionImpl>(std::move(fn)); |
277 | 278 | } |
278 | 279 |
|
279 | | - static std::unique_ptr<cel::Function> WrapFunction( |
280 | | - absl::AnyInvocable<T(U) const> function) { |
| 280 | + template <typename F, typename = std::enable_if_t<std::is_invocable_v<F, U>>> |
| 281 | + static std::unique_ptr<cel::Function> WrapFunction(F&& function) { |
281 | 282 | return WrapFunction( |
282 | | - [function = std::move(function)]( |
| 283 | + [function = std::forward<F>(function)]( |
283 | 284 | U arg1, const google::protobuf::DescriptorPool* absl_nonnull, |
284 | 285 | google::protobuf::MessageFactory* absl_nonnull, |
285 | 286 | google::protobuf::Arena* absl_nonnull) -> T { return function(arg1); }); |
@@ -406,10 +407,11 @@ class BinaryFunctionAdapter |
406 | 407 | return std::make_unique<BinaryFunctionImpl>(std::move(fn)); |
407 | 408 | } |
408 | 409 |
|
409 | | - static std::unique_ptr<cel::Function> WrapFunction( |
410 | | - absl::AnyInvocable<T(U, V) const> function) { |
| 410 | + template <typename F, |
| 411 | + typename = std::enable_if_t<std::is_invocable_v<F, U, V>>> |
| 412 | + static std::unique_ptr<cel::Function> WrapFunction(F&& function) { |
411 | 413 | return WrapFunction( |
412 | | - [function = std::move(function)]( |
| 414 | + [function = std::forward<F>(function)]( |
413 | 415 | U arg1, V arg2, const google::protobuf::DescriptorPool* absl_nonnull, |
414 | 416 | google::protobuf::MessageFactory* absl_nonnull, |
415 | 417 | google::protobuf::Arena* absl_nonnull) -> T { return function(arg1, arg2); }); |
@@ -475,9 +477,10 @@ class TernaryFunctionAdapter |
475 | 477 | return std::make_unique<TernaryFunctionImpl>(std::move(fn)); |
476 | 478 | } |
477 | 479 |
|
478 | | - static std::unique_ptr<cel::Function> WrapFunction( |
479 | | - absl::AnyInvocable<T(U, V, W) const> function) { |
480 | | - return WrapFunction([function = std::move(function)]( |
| 480 | + template <typename F, |
| 481 | + typename = std::enable_if_t<std::is_invocable_v<F, U, V, W>>> |
| 482 | + static std::unique_ptr<cel::Function> WrapFunction(F&& function) { |
| 483 | + return WrapFunction([function = std::forward<F>(function)]( |
481 | 484 | U arg1, V arg2, W arg3, |
482 | 485 | const google::protobuf::DescriptorPool* absl_nonnull, |
483 | 486 | google::protobuf::MessageFactory* absl_nonnull, |
@@ -553,9 +556,10 @@ class QuaternaryFunctionAdapter |
553 | 556 | return std::make_unique<QuaternaryFunctionImpl>(std::move(fn)); |
554 | 557 | } |
555 | 558 |
|
556 | | - static std::unique_ptr<cel::Function> WrapFunction( |
557 | | - absl::AnyInvocable<T(U, V, W, X) const> function) { |
558 | | - return WrapFunction([function = std::move(function)]( |
| 559 | + template <typename F, |
| 560 | + typename = std::enable_if_t<std::is_invocable_v<F, U, V, W, X>>> |
| 561 | + static std::unique_ptr<cel::Function> WrapFunction(F&& function) { |
| 562 | + return WrapFunction([function = std::forward<F>(function)]( |
559 | 563 | U arg1, V arg2, W arg3, X arg4, |
560 | 564 | const google::protobuf::DescriptorPool* absl_nonnull, |
561 | 565 | google::protobuf::MessageFactory* absl_nonnull, |
@@ -670,10 +674,11 @@ class NaryFunctionAdapter |
670 | 674 | return std::make_unique<NaryFunctionImpl>(std::move(fn)); |
671 | 675 | } |
672 | 676 |
|
673 | | - static std::unique_ptr<cel::Function> WrapFunction( |
674 | | - absl::AnyInvocable<T(Args...) const> function) { |
| 677 | + template <typename F, |
| 678 | + typename = std::enable_if_t<std::is_invocable_v<F, Args...>>> |
| 679 | + static std::unique_ptr<cel::Function> WrapFunction(F&& function) { |
675 | 680 | return WrapFunction( |
676 | | - [function = std::move(function)]( |
| 681 | + [function = std::forward<F>(function)]( |
677 | 682 | Args... args, const google::protobuf::DescriptorPool* absl_nonnull, |
678 | 683 | google::protobuf::MessageFactory* absl_nonnull, |
679 | 684 | google::protobuf::Arena* absl_nonnull) -> T { return function(args...); }); |
|
0 commit comments