1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <iterator> 11 12 // template<class Category, class T, class Distance = ptrdiff_t, 13 // class Pointer = T*, class Reference = T&> 14 // struct iterator 15 // { 16 // typedef T value_type; 17 // typedef Distance difference_type; 18 // typedef Pointer pointer; 19 // typedef Reference reference; 20 // typedef Category iterator_category; 21 // }; 22 23 #include <iterator> 24 #include <type_traits> 25 26 struct A {}; 27 28 template <class T> 29 void 30 test2() 31 { 32 typedef std::iterator<std::forward_iterator_tag, T> It; 33 static_assert((std::is_same<typename It::value_type, T>::value), ""); 34 static_assert((std::is_same<typename It::difference_type, std::ptrdiff_t>::value), ""); 35 static_assert((std::is_same<typename It::pointer, T*>::value), ""); 36 static_assert((std::is_same<typename It::reference, T&>::value), ""); 37 static_assert((std::is_same<typename It::iterator_category, std::forward_iterator_tag>::value), ""); 38 } 39 40 template <class T> 41 void 42 test3() 43 { 44 typedef std::iterator<std::bidirectional_iterator_tag, T, short> It; 45 static_assert((std::is_same<typename It::value_type, T>::value), ""); 46 static_assert((std::is_same<typename It::difference_type, short>::value), ""); 47 static_assert((std::is_same<typename It::pointer, T*>::value), ""); 48 static_assert((std::is_same<typename It::reference, T&>::value), ""); 49 static_assert((std::is_same<typename It::iterator_category, std::bidirectional_iterator_tag>::value), ""); 50 } 51 52 template <class T> 53 void 54 test4() 55 { 56 typedef std::iterator<std::random_access_iterator_tag, T, int, const T*> It; 57 static_assert((std::is_same<typename It::value_type, T>::value), ""); 58 static_assert((std::is_same<typename It::difference_type, int>::value), ""); 59 static_assert((std::is_same<typename It::pointer, const T*>::value), ""); 60 static_assert((std::is_same<typename It::reference, T&>::value), ""); 61 static_assert((std::is_same<typename It::iterator_category, std::random_access_iterator_tag>::value), ""); 62 } 63 64 template <class T> 65 void 66 test5() 67 { 68 typedef std::iterator<std::input_iterator_tag, T, long, const T*, const T&> It; 69 static_assert((std::is_same<typename It::value_type, T>::value), ""); 70 static_assert((std::is_same<typename It::difference_type, long>::value), ""); 71 static_assert((std::is_same<typename It::pointer, const T*>::value), ""); 72 static_assert((std::is_same<typename It::reference, const T&>::value), ""); 73 static_assert((std::is_same<typename It::iterator_category, std::input_iterator_tag>::value), ""); 74 } 75 76 int main() 77 { 78 test2<A>(); 79 test3<A>(); 80 test4<A>(); 81 test5<A>(); 82 } 83