Skip to content

Commit 715364e

Browse files
author
Hana Dusíková
committed
combining regex with operators | and >>
1 parent 9619370 commit 715364e

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

include/ctre.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
#include "ctre/functions.hpp"
66
#include "ctre/iterators.hpp"
77
#include "ctre/range.hpp"
8+
#include "ctre/operators.hpp"
89

910
#endif

include/ctre/operators.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef CTRE_V2__CTRE__OPERATORS__HPP
2+
#define CTRE_V2__CTRE__OPERATORS__HPP
3+
4+
template <typename A, typename B> constexpr auto operator|(ctre::regular_expression<A>, ctre::regular_expression<B>) -> ctre::regular_expression<ctre::select<A,B>> {
5+
return {};
6+
}
7+
8+
template <typename A, typename B> constexpr auto operator>>(ctre::regular_expression<A>, ctre::regular_expression<B>) -> ctre::regular_expression<ctre::sequence<A,B>> {
9+
return {};
10+
}
11+
12+
#endif

tests/matching2.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,8 @@ static_assert("[A-Z_a-z]"_ctre.match("a"));
186186
static_assert("[A-Z_a-z]"_ctre.match("_"));
187187
static_assert("[A-Z_a-z]"_ctre.match("Z"));
188188

189+
static_assert(("[a-z]"_ctre >> "[0-9]"_ctre).match("a9"));
190+
static_assert(("a"_ctre | "b"_ctre).match("a"));
191+
static_assert(("a"_ctre | "b"_ctre).match("b"));
192+
static_assert(!("a"_ctre | "b"_ctre).match("c"));
193+

0 commit comments

Comments
 (0)