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 //===----------------------------------------------------------------------===//
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
21 #include <type_traits>
23 #include "test_macros.h"
24 #include "test_iterators.h"
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);
49 #if TEST_STD_VER >= 17
50 static_assert(tests(), "");