1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
13 // template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
14 // requires HasMinus<Iter2, Iter1>
15 // auto operator-(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y) // constexpr in C++17
16 // -> decltype(y.base() - x.base());
21 #include <type_traits>
23 #include "test_macros.h"
24 #include "test_iterators.h"
26 template <class, class, class = void> struct HasMinus
: std::false_type
{};
27 template <class R1
, class R2
> struct HasMinus
<R1
, R2
, decltype((R1() - R2(), void()))> : std::true_type
{};
29 template <class It1
, class It2
>
30 TEST_CONSTEXPR_CXX17
void test(It1 l
, It2 r
, std::ptrdiff_t x
) {
31 const std::reverse_iterator
<It1
> r1(l
);
32 const std::reverse_iterator
<It2
> r2(r
);
33 assert((r1
- r2
) == x
);
36 TEST_CONSTEXPR_CXX17
bool tests() {
37 using PC
= const char*;
40 // Test same base iterator type
45 // Test different (but subtractable) base iterator types
50 // Test non-subtractable base iterator types
51 static_assert( HasMinus
<std::reverse_iterator
<int*>, std::reverse_iterator
<int*> >::value
, "");
52 static_assert( HasMinus
<std::reverse_iterator
<int*>, std::reverse_iterator
<const int*> >::value
, "");
53 #if TEST_STD_VER >= 11
54 static_assert(!HasMinus
<std::reverse_iterator
<int*>, std::reverse_iterator
<char*> >::value
, "");
55 static_assert(!HasMinus
<std::reverse_iterator
<bidirectional_iterator
<int*> >, std::reverse_iterator
<bidirectional_iterator
<int*> > >::value
, "");
61 int main(int, char**) {
64 static_assert(tests(), "");