Skip to content

Commit 48dbcb3

Browse files
committed
Add possibility to use lambda in is-statements
1 parent f4866cf commit 48dbcb3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

include/cpp2util.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,25 @@ auto is( X const& x ) -> bool {
637637
return false;
638638
}
639639

640+
template <typename F, typename X>
641+
struct lambda_wrapper {
642+
F f;
643+
X x;
644+
645+
constexpr lambda_wrapper(F f, X x)
646+
: f{f}, x{x} {}
647+
648+
template <typename T>
649+
auto operator()(T&& t) const {
650+
return f(std::forward<T>(t), x);
651+
}
652+
};
653+
654+
template< lambda_wrapper value, typename X >
655+
auto is( X const& x ) -> bool {
656+
return value(x);
657+
}
658+
640659
//-------------------------------------------------------------------------------------------------------------
641660
// Built-in as (partial)
642661
//

0 commit comments

Comments
 (0)