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 | // check that std::__unwrap_iter() returns the correct type |
10 | |
11 | #include <algorithm> |
12 | #include <cassert> |
13 | #include <string> |
14 | #include <type_traits> |
15 | |
16 | #include "test_iterators.h" |
17 | #include "test_macros.h" |
18 | |
19 | template <class Iter> |
20 | using UnwrapT = decltype(std::__unwrap_iter(std::declval<Iter>())); |
21 | |
22 | template <class Iter> |
23 | using rev_iter = std::reverse_iterator<Iter>; |
24 | |
25 | template <class Iter> |
26 | using rev_rev_iter = rev_iter<rev_iter<Iter> >; |
27 | |
28 | static_assert(std::is_same<UnwrapT<int*>, int*>::value, "" ); |
29 | static_assert(std::is_same<UnwrapT<std::__wrap_iter<int*> >, int*>::value, "" ); |
30 | static_assert(std::is_same<UnwrapT<rev_iter<int*> >, std::reverse_iterator<int*> >::value, "" ); |
31 | static_assert(std::is_same<UnwrapT<rev_rev_iter<int*> >, int*>::value, "" ); |
32 | static_assert(std::is_same<UnwrapT<rev_rev_iter<std::__wrap_iter<int*> > >, int*>::value, "" ); |
33 | static_assert(std::is_same<UnwrapT<rev_rev_iter<rev_iter<std::__wrap_iter<int*> > > >, rev_iter<std::__wrap_iter<int*> > >::value, "" ); |
34 | |
35 | static_assert(std::is_same<UnwrapT<random_access_iterator<int*> >, random_access_iterator<int*> >::value, "" ); |
36 | static_assert(std::is_same<UnwrapT<rev_iter<random_access_iterator<int*> > >, rev_iter<random_access_iterator<int*> > >::value, "" ); |
37 | static_assert(std::is_same<UnwrapT<rev_rev_iter<random_access_iterator<int*> > >, random_access_iterator<int*> >::value, "" ); |
38 | static_assert(std::is_same<UnwrapT<rev_rev_iter<rev_iter<random_access_iterator<int*> > > >, rev_iter<random_access_iterator<int*> > >::value, "" ); |
39 | |
40 | TEST_CONSTEXPR_CXX20 bool test() { |
41 | std::string str = "Banane" ; |
42 | using Iter = std::string::iterator; |
43 | |
44 | assert(std::__unwrap_iter(str.begin()) == str.data()); |
45 | assert(std::__unwrap_iter(str.end()) == str.data() + str.size()); |
46 | assert(std::__unwrap_iter(rev_rev_iter<Iter>(rev_iter<Iter>(str.begin()))) == str.data()); |
47 | assert(std::__unwrap_iter(rev_rev_iter<Iter>(rev_iter<Iter>(str.end()))) == str.data() + str.size()); |
48 | |
49 | return true; |
50 | } |
51 | |
52 | int main(int, char**) { |
53 | test(); |
54 | #if TEST_STD_VER > 17 |
55 | static_assert(test()); |
56 | #endif |
57 | |
58 | return 0; |
59 | } |
60 | |