// S : tags c++ fin $TAGS // S : expect --result valid // S : cc -o test.bc -std=c++2a $CC_OPT $file // S : verify -o nofail:malloc $V_OPT test.bc //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // template // Iter::difference_type // distance(Iter first, Iter last); // // template // Iter::difference_type // distance(Iter first, Iter last); #include #include #include "test_macros.h" #include "test_iterators.h" template void test(It first, It last, typename std::iterator_traits::difference_type x) { assert(std::distance(first, last) == x); } #if TEST_STD_VER > 14 template constexpr bool constexpr_test(It first, It last, typename std::iterator_traits::difference_type x) { return std::distance(first, last) == x; } #endif int main(int, char**) { { const char* s = "1234567890"; test(input_iterator(s), input_iterator(s+10), 10); test(forward_iterator(s), forward_iterator(s+10), 10); test(bidirectional_iterator(s), bidirectional_iterator(s+10), 10); test(random_access_iterator(s), random_access_iterator(s+10), 10); test(s, s+10, 10); } #if TEST_STD_VER > 14 { constexpr const char* s = "1234567890"; static_assert( constexpr_test(input_iterator(s), input_iterator(s+10), 10), ""); static_assert( constexpr_test(forward_iterator(s), forward_iterator(s+10), 10), ""); static_assert( constexpr_test(bidirectional_iterator(s), bidirectional_iterator(s+10), 10), ""); static_assert( constexpr_test(random_access_iterator(s), random_access_iterator(s+10), 10), ""); static_assert( constexpr_test(s, s+10, 10), ""); } #endif return 0; }