| 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 | |
| 11 | // template <class BidirectionalIterator> class sub_match; |
| 12 | |
| 13 | // void swap(sub_match& s) noexcept(see below); |
| 14 | |
| 15 | #include <regex> |
| 16 | #include <cassert> |
| 17 | #include "test_macros.h" |
| 18 | |
| 19 | int main(int, char**) { |
| 20 | { |
| 21 | using CharT = char; |
| 22 | using SM = std::sub_match<const CharT*>; |
| 23 | const CharT s1[] = {'1', '2', '3', 0}; |
| 24 | SM sm1; |
| 25 | sm1.first = s1; |
| 26 | sm1.second = s1 + 3; |
| 27 | sm1.matched = true; |
| 28 | |
| 29 | SM sm2; |
| 30 | const CharT s2[] = {'c', 'a', 't', 0}; |
| 31 | sm2.first = s2; |
| 32 | sm2.second = s2 + 3; |
| 33 | sm2.matched = false; |
| 34 | |
| 35 | sm1.swap(sm2); |
| 36 | |
| 37 | assert(sm1.first == s2); |
| 38 | assert(sm1.second == s2 + 3); |
| 39 | assert(!sm1.matched); |
| 40 | |
| 41 | assert(sm2.first == s1); |
| 42 | assert(sm2.second == s1 + 3); |
| 43 | assert(sm2.matched); |
| 44 | |
| 45 | ASSERT_NOEXCEPT(sm1.swap(sm2)); |
| 46 | } |
| 47 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 48 | { |
| 49 | using CharT = wchar_t; |
| 50 | using SM = std::sub_match<const CharT*>; |
| 51 | const CharT s1[] = {L'1', L'2', L'3', 0}; |
| 52 | SM sm1; |
| 53 | sm1.first = s1; |
| 54 | sm1.second = s1 + 3; |
| 55 | sm1.matched = true; |
| 56 | |
| 57 | SM sm2; |
| 58 | const CharT s2[] = {L'c', L'a', L't', 0}; |
| 59 | sm2.first = s2; |
| 60 | sm2.second = s2 + 3; |
| 61 | sm2.matched = false; |
| 62 | |
| 63 | sm1.swap(sm2); |
| 64 | |
| 65 | assert(sm1.first == s2); |
| 66 | assert(sm1.second == s2 + 3); |
| 67 | assert(!sm1.matched); |
| 68 | |
| 69 | assert(sm2.first == s1); |
| 70 | assert(sm2.second == s1 + 3); |
| 71 | assert(sm2.matched); |
| 72 | |
| 73 | ASSERT_NOEXCEPT(sm1.swap(sm2)); |
| 74 | } |
| 75 | #endif |
| 76 | } |
| 77 | |