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 // template <class _Iterator>
10 // struct __bounded_iter;
11 //
12 // std::pointer_traits specialization
13 
14 #include <cassert>
15 #include <cstddef>
16 #include <iterator>
17 #include <type_traits>
18 
19 #include "test_iterators.h"
20 #include "test_macros.h"
21 
22 template <class Iter>
tests()23 TEST_CONSTEXPR_CXX14 bool tests() {
24   using BoundedIter = std::__bounded_iter<Iter>;
25   using PointerTraits = std::pointer_traits<BoundedIter>;
26   using BasePointerTraits = std::pointer_traits<Iter>;
27   static_assert(std::is_same<typename PointerTraits::pointer, BoundedIter>::value, "");
28   static_assert(std::is_same<typename PointerTraits::element_type, typename BasePointerTraits::element_type>::value, "");
29   static_assert(std::is_same<typename PointerTraits::difference_type, typename BasePointerTraits::difference_type>::value, "");
30 
31   {
32     int array[]                           = {0, 1, 2, 3, 4};
33     int* b                                = array + 0;
34     int* e                                = array + 5;
35     std::__bounded_iter<Iter> const iter1 = std::__make_bounded_iter(Iter(b), Iter(b), Iter(e));
36     std::__bounded_iter<Iter> const iter2 = std::__make_bounded_iter(Iter(e), Iter(b), Iter(e));
37     assert(std::__to_address(iter1) == b); // in-bounds iterator
38     assert(std::__to_address(iter2) == e); // out-of-bounds iterator
39 #if TEST_STD_VER > 17
40     assert(std::to_address(iter1) == b); // in-bounds iterator
41     assert(std::to_address(iter2) == e); // out-of-bounds iterator
42 #endif
43   }
44 
45   return true;
46 }
47 
main(int,char **)48 int main(int, char**) {
49   tests<int*>();
50 #if TEST_STD_VER > 11
51   static_assert(tests<int*>(), "");
52 #endif
53 
54 #if TEST_STD_VER > 17
55   tests<contiguous_iterator<int*> >();
56   static_assert(tests<contiguous_iterator<int*> >(), "");
57 #endif
58 
59   return 0;
60 }
61