1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: libcpp-no-deduction-guides
14 // template<class ForwardIterator>
15 // basic_regex(ForwardIterator, ForwardIterator,
16 // regex_constants::syntax_option_type = regex_constants::ECMAScript)
17 // -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>;
26 #include "test_macros.h"
27 #include "test_iterators.h"
28 #include "test_allocator.h"
30 using namespace std::literals
;
37 // Test the explicit deduction guides
39 // basic_regex(ForwardIterator, ForwardIterator)
40 std::string
s1("\\(a\\)");
41 std::basic_regex
re(s1
.begin(), s1
.end());
43 static_assert(std::is_same_v
<decltype(re
), std::basic_regex
<char>>, "");
44 assert(re
.flags() == std::regex_constants::ECMAScript
);
45 assert(re
.mark_count() == 0);
49 std::wstring
s1(L
"\\(a\\)");
50 std::basic_regex
re(s1
.begin(), s1
.end(), std::regex_constants::basic
);
52 static_assert(std::is_same_v
<decltype(re
), std::basic_regex
<wchar_t>>, "");
53 assert(re
.flags() == std::regex_constants::basic
);
54 assert(re
.mark_count() == 1);
57 // Test the implicit deduction guides
59 // basic_regex(string);
60 std::basic_regex
re("(a([bc]))"s
);
61 static_assert(std::is_same_v
<decltype(re
), std::basic_regex
<char>>, "");
62 assert(re
.flags() == std::regex_constants::ECMAScript
);
63 assert(re
.mark_count() == 2);
67 // basic_regex(string, flag_type);
68 std::basic_regex
re(L
"(a([bc]))"s
, std::regex_constants::awk
);
69 static_assert(std::is_same_v
<decltype(re
), std::basic_regex
<wchar_t>>, "");
70 assert(re
.flags() == std::regex_constants::awk
);
71 assert(re
.mark_count() == 2);
75 // basic_regex(const charT*);
76 std::basic_regex
re("ABCDE");
77 static_assert(std::is_same_v
<decltype(re
), std::basic_regex
<char>>, "");
78 assert(re
.flags() == std::regex_constants::ECMAScript
);
79 assert(re
.mark_count() == 0);
83 // basic_regex(const charT*, flag_type);
84 std::basic_regex
re(L
"ABCDE", std::regex_constants::grep
);
85 static_assert(std::is_same_v
<decltype(re
), std::basic_regex
<wchar_t>>, "");
86 assert(re
.flags() == std::regex_constants::grep
);
87 assert(re
.mark_count() == 0);
91 // basic_regex(const charT*, size_t);
92 std::basic_regex
re("ABCDEDEF", 7);
93 static_assert(std::is_same_v
<decltype(re
), std::basic_regex
<char>>, "");
94 assert(re
.flags() == std::regex_constants::ECMAScript
);
95 assert(re
.mark_count() == 0);
99 // basic_regex(const charT*, size_t, flag_type);
100 std::basic_regex
re(L
"ABCDEDEF", 8, std::regex_constants::awk
);
101 static_assert(std::is_same_v
<decltype(re
), std::basic_regex
<wchar_t>>, "");
102 assert(re
.flags() == std::regex_constants::awk
);
103 assert(re
.mark_count() == 0);
107 // basic_regex(const basic_regex &);
108 std::basic_regex
<char> source
;
109 std::basic_regex
re(source
);
110 static_assert(std::is_same_v
<decltype(re
), std::basic_regex
<char>>, "");
111 assert(re
.flags() == source
.flags());
112 assert(re
.mark_count() == source
.mark_count());
116 // template<class ST, class SA>
117 // explicit basic_regex(const basic_string<charT, ST, SA>& p,
118 // flag_type f = regex_constants::ECMAScript);
122 // basic_regex(initializer_list);
123 std::basic_regex
re({'A', 'B', 'F', 'E', 'D'});
124 static_assert(std::is_same_v
<decltype(re
), std::basic_regex
<char>>, "");
125 assert(re
.flags() == std::regex_constants::ECMAScript
);
126 assert(re
.mark_count() == 0);
130 // basic_regex(initializer_list, flag_type);
131 std::basic_regex
re({L
'A', L
'B', L
'F', L
'E', L
'D'}, std::regex_constants::grep
);
132 static_assert(std::is_same_v
<decltype(re
), std::basic_regex
<wchar_t>>, "");
133 assert(re
.flags() == std::regex_constants::grep
);
134 assert(re
.mark_count() == 0);