deduct.pass.cpp 4.2 KB

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