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 // <iterator> 10 11 // template<class Category, class T, class Distance = ptrdiff_t, 12 // class Pointer = T*, class Reference = T&> 13 // struct iterator 14 // { 15 // typedef T value_type; 16 // typedef Distance difference_type; 17 // typedef Pointer pointer; 18 // typedef Reference reference; 19 // typedef Category iterator_category; 20 // }; 21 22 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS 23 24 #include <iterator> 25 #include <cstddef> 26 #include <type_traits> 27 28 #include "test_macros.h" 29 30 struct A {}; 31 32 template <class T> 33 void 34 test2() 35 { 36 typedef std::iterator<std::forward_iterator_tag, T> It; 37 static_assert((std::is_same<typename It::value_type, T>::value), ""); 38 static_assert((std::is_same<typename It::difference_type, std::ptrdiff_t>::value), ""); 39 static_assert((std::is_same<typename It::pointer, T*>::value), ""); 40 static_assert((std::is_same<typename It::reference, T&>::value), ""); 41 static_assert((std::is_same<typename It::iterator_category, std::forward_iterator_tag>::value), ""); 42 } 43 44 template <class T> 45 void 46 test3() 47 { 48 typedef std::iterator<std::bidirectional_iterator_tag, T, short> It; 49 static_assert((std::is_same<typename It::value_type, T>::value), ""); 50 static_assert((std::is_same<typename It::difference_type, short>::value), ""); 51 static_assert((std::is_same<typename It::pointer, T*>::value), ""); 52 static_assert((std::is_same<typename It::reference, T&>::value), ""); 53 static_assert((std::is_same<typename It::iterator_category, std::bidirectional_iterator_tag>::value), ""); 54 } 55 56 template <class T> 57 void 58 test4() 59 { 60 typedef std::iterator<std::random_access_iterator_tag, T, int, const T*> It; 61 static_assert((std::is_same<typename It::value_type, T>::value), ""); 62 static_assert((std::is_same<typename It::difference_type, int>::value), ""); 63 static_assert((std::is_same<typename It::pointer, const T*>::value), ""); 64 static_assert((std::is_same<typename It::reference, T&>::value), ""); 65 static_assert((std::is_same<typename It::iterator_category, std::random_access_iterator_tag>::value), ""); 66 } 67 68 template <class T> 69 void 70 test5() 71 { 72 typedef std::iterator<std::input_iterator_tag, T, long, const T*, const T&> It; 73 static_assert((std::is_same<typename It::value_type, T>::value), ""); 74 static_assert((std::is_same<typename It::difference_type, long>::value), ""); 75 static_assert((std::is_same<typename It::pointer, const T*>::value), ""); 76 static_assert((std::is_same<typename It::reference, const T&>::value), ""); 77 static_assert((std::is_same<typename It::iterator_category, std::input_iterator_tag>::value), ""); 78 } 79 80 int main(int, char**) 81 { 82 test2<A>(); 83 test3<A>(); 84 test4<A>(); 85 test5<A>(); 86 87 return 0; 88 } 89