Template Class Pattern#
Defined in File pattern_match.h
Class Documentation#
-
template<typename Derived>
class Pattern# Base class of all the patterns.
There are two major member functions supported by each pattern.
Match: checks if value matches the pattern.
Eval: construct a new value based on matched values in PVar.
We use curiously recurring template pattern to construct expression templates.
- Template Parameters:
Derived – The type of the derived class.
Public Types
-
using Nested = Derived#
Nested storage type in the expression.
Depending on the Derived class, Nested can be Derived (nest by value) or const Derived& (nest by reference).
The trick of Nested typedef originates from Eigen.
Note
We use nest by value for intermediate expressions, and nest by reference for PVars.
Public Functions
-
template<typename NodeType>
inline bool Match(const NodeType &value) const# Check if value matches the current pattern.
This call also populates the PVars with matched value. The values in PVars are valid until the next call to Match.
- Parameters:
value – The value to be matched against
- Returns:
whether value matches the pattern.
-
template<typename NodeType, typename Condition>
inline bool Match(const NodeType &value, Condition cond) const# Check if value matches the current pattern.
This call also populates the PVars with matched value. The values in PVars are valid until the next call to Match.
- Parameters:
value – The value to be matched against
cond – A callable that performs additional validation, returning true if the match passes. This will typically be a lambda function written in terms of the filled PVars.
- Returns:
whether value matches the pattern.