Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- template <const char Expression[], char C = Expression[0], size_t index = 0>
- struct myRegex
- {
- myRegex(string&& _str): str(_str) {}
- bool isMatch()
- {
- return str.front()==C ? myRegex<Expression, Expression[index+1], index+1>(str.substr(1)).isMatch() : false;
- }
- private:
- string str;
- };
- template <const char Expression[], size_t index>
- struct myRegex<Expression, '?', index>
- {
- myRegex(string&& _str): str(_str) {}
- bool isMatch()
- {
- return myRegex<Expression, Expression[index+1], index+1>(str.substr(1)).isMatch();
- }
- private:
- string str;
- };
- template <const char Expression[], size_t index>
- struct myRegex<Expression, '\0', index>
- {
- myRegex(string&& _str): str(_str) {}
- bool isMatch()
- {
- return true;
- }
- private:
- string str;
- };
- extern constexpr char Expression[] = "a?b";
- int main(void)
- {
- cout << myRegex<Expression>("a+b").isMatch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement