50 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// template <class _Iterator>10// struct __bounded_iter;11//12// std::pointer_traits specialization13 14#include <__cxx03/__iterator/bounded_iter.h>15#include <cassert>16#include <cstddef>17#include <memory>18#include <type_traits>19 20#include "test_iterators.h"21#include "test_macros.h"22 23template <class Iter>24TEST_CONSTEXPR_CXX14 bool tests() {25 using BoundedIter = std::__bounded_iter<Iter>;26 using PointerTraits = std::pointer_traits<BoundedIter>;27 using BasePointerTraits = std::pointer_traits<Iter>;28 static_assert(std::is_same<typename PointerTraits::pointer, BoundedIter>::value, "");29 static_assert(std::is_same<typename PointerTraits::element_type, typename BasePointerTraits::element_type>::value, "");30 static_assert(std::is_same<typename PointerTraits::difference_type, typename BasePointerTraits::difference_type>::value, "");31 32 {33 int array[] = {0, 1, 2, 3, 4};34 int* b = array + 0;35 int* e = array + 5;36 std::__bounded_iter<Iter> const iter1 = std::__make_bounded_iter(Iter(b), Iter(b), Iter(e));37 std::__bounded_iter<Iter> const iter2 = std::__make_bounded_iter(Iter(e), Iter(b), Iter(e));38 assert(std::__to_address(iter1) == b); // in-bounds iterator39 assert(std::__to_address(iter2) == e); // out-of-bounds iterator40 }41 42 return true;43}44 45int main(int, char**) {46 tests<int*>();47 48 return 0;49}50