deduct.pass.cpp
4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <regex>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// UNSUPPORTED: libcpp-no-deduction-guides
// template<class ForwardIterator>
// basic_regex(ForwardIterator, ForwardIterator,
// regex_constants::syntax_option_type = regex_constants::ECMAScript)
// -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>;
#include <regex>
#include <string>
#include <iterator>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
#include "test_iterators.h"
#include "test_allocator.h"
using namespace std::literals;
struct A {};
int main(int, char**)
{
// Test the explicit deduction guides
{
// basic_regex(ForwardIterator, ForwardIterator)
std::string s1("\\(a\\)");
std::basic_regex re(s1.begin(), s1.end());
static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, "");
assert(re.flags() == std::regex_constants::ECMAScript);
assert(re.mark_count() == 0);
}
{
std::wstring s1(L"\\(a\\)");
std::basic_regex re(s1.begin(), s1.end(), std::regex_constants::basic);
static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, "");
assert(re.flags() == std::regex_constants::basic);
assert(re.mark_count() == 1);
}
// Test the implicit deduction guides
{
// basic_regex(string);
std::basic_regex re("(a([bc]))"s);
static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, "");
assert(re.flags() == std::regex_constants::ECMAScript);
assert(re.mark_count() == 2);
}
{
// basic_regex(string, flag_type);
std::basic_regex re(L"(a([bc]))"s, std::regex_constants::awk);
static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, "");
assert(re.flags() == std::regex_constants::awk);
assert(re.mark_count() == 2);
}
{
// basic_regex(const charT*);
std::basic_regex re("ABCDE");
static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, "");
assert(re.flags() == std::regex_constants::ECMAScript);
assert(re.mark_count() == 0);
}
{
// basic_regex(const charT*, flag_type);
std::basic_regex re(L"ABCDE", std::regex_constants::grep);
static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, "");
assert(re.flags() == std::regex_constants::grep);
assert(re.mark_count() == 0);
}
{
// basic_regex(const charT*, size_t);
std::basic_regex re("ABCDEDEF", 7);
static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, "");
assert(re.flags() == std::regex_constants::ECMAScript);
assert(re.mark_count() == 0);
}
{
// basic_regex(const charT*, size_t, flag_type);
std::basic_regex re(L"ABCDEDEF", 8, std::regex_constants::awk);
static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, "");
assert(re.flags() == std::regex_constants::awk);
assert(re.mark_count() == 0);
}
{
// basic_regex(const basic_regex &);
std::basic_regex<char> source;
std::basic_regex re(source);
static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, "");
assert(re.flags() == source.flags());
assert(re.mark_count() == source.mark_count());
}
{
// template<class ST, class SA>
// explicit basic_regex(const basic_string<charT, ST, SA>& p,
// flag_type f = regex_constants::ECMAScript);
}
{
// basic_regex(initializer_list);
std::basic_regex re({'A', 'B', 'F', 'E', 'D'});
static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, "");
assert(re.flags() == std::regex_constants::ECMAScript);
assert(re.mark_count() == 0);
}
{
// basic_regex(initializer_list, flag_type);
std::basic_regex re({L'A', L'B', L'F', L'E', L'D'}, std::regex_constants::grep);
static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, "");
assert(re.flags() == std::regex_constants::grep);
assert(re.mark_count() == 0);
}
return 0;
}