summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc
blob: 8f2d73c520f98724e6d2d3083d2452724624f091 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright (C) 2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }

#include <iterator>

template<int>
struct Iter
{
  using iterator_category = std::random_access_iterator_tag;
  using value_type = int;
  using pointer = int*;
  using reference = int&;
  using difference_type = std::ptrdiff_t;

  Iter();

  Iter& operator++();
  Iter operator++(int);
  Iter& operator--();
  Iter operator--(int);
  int& operator*() const;
  int* operator->() const;

  int& operator[](difference_type) const;

  Iter& operator+=(difference_type);
  Iter& operator-=(difference_type);

  template<int N> friend Iter operator+(Iter<N>, difference_type);
  template<int N> friend Iter operator+(difference_type, Iter<N>);
  template<int N> friend Iter operator-(Iter<N>, difference_type);
  template<int N> friend difference_type operator-(Iter<N>, Iter<N>);

  // Define the full set of operators for same-type comparisons
  template<int N> friend bool operator==(Iter<N>, Iter<N>); // synthesizes !=
  template<int N> friend bool operator<(Iter<N>, Iter<N>);
  template<int N> friend bool operator>(Iter<N>, Iter<N>);
  template<int N> friend bool operator<=(Iter<N>, Iter<N>);
  template<int N> friend bool operator>=(Iter<N>, Iter<N>);
};


static_assert( std::random_access_iterator<Iter<0>> );

int   operator==(Iter<0>, long*);
void* operator< (Iter<1>, long*);
bool& operator< (long*, Iter<2>);

using std::move_iterator;

static_assert( std::three_way_comparable<move_iterator<Iter<0>>> );

move_iterator<Iter<0>> l0{Iter<0>()};
move_iterator<Iter<1>> l1{Iter<1>()};
move_iterator<Iter<2>> l2{Iter<2>()};
move_iterator<long*> r{nullptr};

bool b0 = l0 == r;
bool b1 = l0 != r;
bool b2 = l1 < r;
bool b3 = l2 > r;
bool b4 = l2 <= r;
bool b5 = l1 >= r;

template<int N>
  concept has_eq
    = requires (move_iterator<Iter<N>> l, move_iterator<long*> r)
      { l == r; };

template<int N>
  concept has_ne
    = requires (move_iterator<Iter<N>> l, move_iterator<long*> r)
      { l != r; };

template<int N>
  concept has_lt
    = requires (move_iterator<Iter<N>> l, move_iterator<long*> r)
      { l < r; };

template<int N>
  concept has_gt
    = requires (move_iterator<Iter<N>> l, move_iterator<long*> r)
      { l > r; };

template<int N>
  concept has_le
    = requires (move_iterator<Iter<N>> l, move_iterator<long*> r)
      { l <= r; };

template<int N>
  concept has_ge
    = requires (move_iterator<Iter<N>> l, move_iterator<long*> r)
      { l >= r; };

static_assert( has_eq<0> );
static_assert( ! has_eq<1> );
static_assert( ! has_eq<2> );

static_assert( has_ne<0> ); // uses synthesized operator!=
static_assert( ! has_ne<1> );
static_assert( ! has_ne<2> );

static_assert( ! has_lt<0> );
static_assert( has_lt<1> );
static_assert( ! has_lt<2> );

static_assert( ! has_gt<0> );
static_assert( ! has_gt<1> );
static_assert( has_gt<2> );

static_assert( ! has_le<0> );
static_assert( ! has_le<1> );
static_assert( has_le<2> );

static_assert( ! has_ge<0> );
static_assert( has_ge<1> );
static_assert( ! has_ge<2> );