Pointer matching
#104
|
Hi, auto ptr = std::make_unique<Derived1>();
...
using namespace matchit;
// match ptr or ptr.get() ? currently only *ptr works?
match (ptr) (
pattern | as<Derived1>(_) = []{ std::cout << "Derived 1"; },
pattern | as<Derived2>(_) = []{ std::cout << "Derived 2"; },
pattern | _ = []{});Thanks |
Answered by
BowenFu
Dec 19, 2025
Replies: 2 comments 1 reply
|
@FishAI, can you try something like this? auto ptr = std::make_unique<Derived1>();
using namespace matchit;
// match ptr or ptr.get() ? currently only *ptr works?
match (ptr) (
pattern | some(as<Derived1>(_)) = []{ std::cout << "Derived 1"; },
pattern | some(as<Derived2>(_)) = []{ std::cout << "Derived 2"; },
pattern | _ = []{}); |
0 replies
Answer selected by
FishAI
|
Nice, it works. I think it would be good to show this usage in the readme. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@FishAI, can you try something like this?