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