AMDGPU: Fix verifier assert with out of bounds subregister indexes (#119799)
[llvm-project.git] / libcxx / test / std / iterators / iterator.primitives / iterator.operations / distance.pass.cpp
blob13caefff92365d16d57233a312cfa18d415a4a6a
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 //===----------------------------------------------------------------------===//
9 // <iterator>
11 // template <InputIterator Iter>
12 // Iter::difference_type
13 // distance(Iter first, Iter last); // constexpr in C++17
15 // template <RandomAccessIterator Iter>
16 // Iter::difference_type
17 // distance(Iter first, Iter last); // constexpr in C++17
19 #include <iterator>
20 #include <cassert>
21 #include <type_traits>
23 #include "test_macros.h"
24 #include "test_iterators.h"
26 template <class It>
27 TEST_CONSTEXPR_CXX17
28 void check_distance(It first, It last, typename std::iterator_traits<It>::difference_type dist)
30 typedef typename std::iterator_traits<It>::difference_type Difference;
31 static_assert(std::is_same<decltype(std::distance(first, last)), Difference>::value, "");
32 assert(std::distance(first, last) == dist);
35 TEST_CONSTEXPR_CXX17 bool tests()
37 const char* s = "1234567890";
38 check_distance(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), 10);
39 check_distance(forward_iterator<const char*>(s), forward_iterator<const char*>(s+10), 10);
40 check_distance(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s+10), 10);
41 check_distance(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+10), 10);
42 check_distance(s, s+10, 10);
43 return true;
46 int main(int, char**)
48 tests();
49 #if TEST_STD_VER >= 17
50 static_assert(tests(), "");
51 #endif
52 return 0;