blob: 47e5a1dba7f609313553d8c19824c4250edf675f [file] [log] [blame]
Marshall Clowedd5e292018-05-23 01:57:02 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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
Marshall Clowedd5e292018-05-23 01:57:02 +00006//
7//===----------------------------------------------------------------------===//
8
9// <regex>
10// UNSUPPORTED: c++98, c++03, c++11, c++14
11// UNSUPPORTED: libcpp-no-deduction-guides
12
13
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>;
Stephan T. Lavavejcb0d2052018-06-14 00:12:20 +000018
Marshall Clowedd5e292018-05-23 01:57:02 +000019
20#include <regex>
21#include <string>
22#include <iterator>
23#include <cassert>
24#include <cstddef>
25
26#include "test_macros.h"
27#include "test_iterators.h"
28#include "test_allocator.h"
29
30using namespace std::literals;
31
32struct A {};
33
JF Bastien2df59c52019-02-04 20:31:13 +000034int main(int, char**)
Marshall Clowedd5e292018-05-23 01:57:02 +000035{
Stephan T. Lavavejcb0d2052018-06-14 00:12:20 +000036
Marshall Clowedd5e292018-05-23 01:57:02 +000037// Test the explicit deduction guides
38 {
39// basic_regex(ForwardIterator, ForwardIterator)
40 std::string s1("\\(a\\)");
41 std::basic_regex re(s1.begin(), s1.end());
42
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);
46 }
47
48 {
49 std::wstring s1(L"\\(a\\)");
50 std::basic_regex re(s1.begin(), s1.end(), std::regex_constants::basic);
51
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);
55 }
Stephan T. Lavavejcb0d2052018-06-14 00:12:20 +000056
Marshall Clowedd5e292018-05-23 01:57:02 +000057// Test the implicit deduction guides
58 {
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);
64 }
65
66 {
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);
72 }
73
74 {
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);
80 }
81
82 {
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);
88 }
Stephan T. Lavavejcb0d2052018-06-14 00:12:20 +000089
Marshall Clowedd5e292018-05-23 01:57:02 +000090 {
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);
96 }
97
98 {
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);
104 }
105
106 {
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());
113 }
114
115 {
116// template<class ST, class SA>
117// explicit basic_regex(const basic_string<charT, ST, SA>& p,
118// flag_type f = regex_constants::ECMAScript);
119 }
120
121 {
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);
127 }
128
129 {
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);
135 }
JF Bastien2df59c52019-02-04 20:31:13 +0000136
137 return 0;
Marshall Clowedd5e292018-05-23 01:57:02 +0000138}