Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,35 @@ struct Square : Shape {};

auto getClassName(Shape const &s)
{
using namespace matchit;
return match(s)(
pattern | as<Circle>(_) = "Circle",
pattern | as<Square>(_) = "Square"
);
}
```

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>(_)) = "Circle",
pattern | some(as<Square>(_)) = "Square",
pattern | _ = "nullptr"
);
}
```

As pattern is not an atomic pattern, either. It is composed via

```C++
Expand Down
Loading