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 // <memory> 11 12 // template <class Ptr> 13 // struct pointer_traits 14 // { 15 // typedef <details> difference_type; 16 // ... 17 // }; 18 19 #include <memory> 20 #include <type_traits> 21 22 #include "test_macros.h" 23 24 struct A 25 { 26 typedef short element_type; 27 typedef char difference_type; 28 }; 29 30 struct B 31 { 32 typedef short element_type; 33 }; 34 35 template <class T> 36 struct C {}; 37 38 template <class T> 39 struct D 40 { 41 typedef char difference_type; 42 }; 43 44 template <class T> 45 struct E 46 { 47 static int difference_type; 48 }; 49 50 template <class T> 51 struct F { 52 private: 53 typedef int difference_type; 54 }; 55 56 int main() 57 { 58 static_assert((std::is_same<std::pointer_traits<A>::difference_type, char>::value), ""); 59 static_assert((std::is_same<std::pointer_traits<B>::difference_type, std::ptrdiff_t>::value), ""); 60 static_assert((std::is_same<std::pointer_traits<C<double> >::difference_type, std::ptrdiff_t>::value), ""); 61 static_assert((std::is_same<std::pointer_traits<D<int> >::difference_type, char>::value), ""); 62 static_assert((std::is_same<std::pointer_traits<E<int> >::difference_type, std::ptrdiff_t>::value), ""); 63 #if TEST_STD_VER >= 11 64 static_assert((std::is_same<std::pointer_traits<F<int>>::difference_type, std::ptrdiff_t>::value), ""); 65 #endif 66 } 67