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++