Category : pattern-matching

Suppose I have a set of types : constexpr std::tuple<int,double,string> my_types; a set of values to identify them: constexpr std::array<const char*,3> my_ids = {"int","double","string"}; // const char* instead of string to be constexpr-compatible and an overload set template<class T> bool my_fun(my_type complex_object) { /* some treatment depending on type T */ } I have a ..

Read more

I’ve come across the pattern matching proposal in C++, and I tried to compile Example 4.6 about expression trees. Here’s the extracted code: #include <memory> #include <variant> struct Expr; struct Neg { std::shared_ptr<Expr> expr; }; struct Add { std::shared_ptr<Expr> lhs, rhs; }; struct Mul { std::shared_ptr<Expr> lhs, rhs; }; struct Expr : std::variant<int, Neg, Add, ..

Read more

I have a function which takes a string(matcher) and a file as input arguments(content). The function returns all the strings from content that match with the matcher. Instead of using direct regex, matcher string can use variables that are predefined : symbol_only, number_only, one_more_variable. These variables are associated with certain regex patterns. Each variable can ..

Read more