deduct.pass.cpp 4.2 KB

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