]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.ops/reverse.iter.op==/test.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / iterators / predef.iterators / reverse.iterators / reverse.iter.ops / reverse.iter.op== / test.pass.cpp
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
10 // <iterator>
11
12 // reverse_iterator
13
14 // template <BidirectionalIterator Iter1, BidirectionalIterator Iter2>
15 //   requires HasEqualTo<Iter1, Iter2>
16 //   constexpr bool
17 //   operator==(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y);
18 //
19 //   constexpr in c++17
20
21 #include <iterator>
22 #include <cassert>
23
24 #include "test_macros.h"
25 #include "test_iterators.h"
26
27 template <class It>
28 void
29 test(It l, It r, bool x)
30 {
31     const std::reverse_iterator<It> r1(l);
32     const std::reverse_iterator<It> r2(r);
33     assert((r1 == r2) == x);
34 }
35
36 int main()
37 {
38     const char* s = "1234567890";
39     test(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s), true);
40     test(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s+1), false);
41     test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s), true);
42     test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), false);
43     test(s, s, true);
44     test(s, s+1, false);
45
46 #if TEST_STD_VER > 14
47     {
48         constexpr const char *p = "123456789";
49         typedef std::reverse_iterator<const char *> RI;
50         constexpr RI it1 = std::make_reverse_iterator(p);
51         constexpr RI it2 = std::make_reverse_iterator(p);
52         constexpr RI it3 = std::make_reverse_iterator(p+1);
53         static_assert( (it1 == it2), "");
54         static_assert(!(it1 == it3), "");
55     }
56 #endif
57
58 }