From 24d17dd912b3918f94a21f5005391fb40006491b Mon Sep 17 00:00:00 2001 From: FishAI <54666184+FishAI@users.noreply.github.com> Date: Fri, 19 Dec 2025 17:26:17 +0100 Subject: [PATCH] Update README.md Added an example for pointer matching Signed-off-by: FishAI <54666184+FishAI@users.noreply.github.com> --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 93a486b..3ceeb5d 100644 --- a/README.md +++ b/README.md @@ -549,6 +549,7 @@ struct Square : Shape {}; auto getClassName(Shape const &s) { + using namespace matchit; return match(s)( pattern | as(_) = "Circle", pattern | as(_) = "Square" @@ -556,6 +557,27 @@ auto getClassName(Shape const &s) } ``` +or as raw or smart pointers, combining the As with the Some pattern + +```C++ +struct Shape +{ + virtual ~Shape() = default; +}; +struct Circle : Shape {}; +struct Square : Shape {}; + +auto getClassName(Shape const *s) +{ + using namespace matchit; + return match(s)( + pattern | some(as(_)) = "Circle", + pattern | some(as(_)) = "Square", + pattern | _ = "nullptr" + ); +} +``` + As pattern is not an atomic pattern, either. It is composed via ```C++