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 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: libcpp-no-concepts
11 
12 // ranges::prev
13 // Make sure we're SFINAE-friendly when the template argument constraints are not met.
14 
15 #include <iterator>
16 
17 #include <cstddef>
18 #include <utility>
19 #include "test_iterators.h"
20 
21 template <class ...Args>
22 concept has_ranges_prev = requires (Args&& ...args) {
23   { std::ranges::prev(std::forward<Args>(args)...) };
24 };
25 
26 using It = forward_iterator<int*>;
27 static_assert(!has_ranges_prev<It>);
28 static_assert(!has_ranges_prev<It, std::ptrdiff_t>);
29 static_assert(!has_ranges_prev<It, std::ptrdiff_t, It>);
30 
31 // Test the test
32 using It2 = bidirectional_iterator<int*>;
33 static_assert(has_ranges_prev<It2>);
34 static_assert(has_ranges_prev<It2, std::ptrdiff_t>);
35 static_assert(has_ranges_prev<It2, std::ptrdiff_t, It2>);
36