boost_no_std_iter_traits.ipp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // (C) Copyright John Maddock 2001.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/config for the most recent version.
  6. // MACRO: BOOST_NO_STD_ITERATOR_TRAITS
  7. // TITLE: std::iterator_traits
  8. // DESCRIPTION: The compiler does not provide a standard
  9. // compliant implementation of std::iterator_traits.
  10. // Note that the compiler may still have a non-standard
  11. // implementation.
  12. #include <iterator>
  13. #include <stddef.h>
  14. namespace boost_no_std_iterator_traits{
  15. struct UDT_iterator
  16. {
  17. typedef int value_type;
  18. typedef ptrdiff_t difference_type;
  19. typedef int* pointer;
  20. typedef int& reference;
  21. typedef std::input_iterator_tag iterator_category;
  22. };
  23. struct UDT{};
  24. int test()
  25. {
  26. std::iterator_traits<UDT_iterator>::value_type v = 0;
  27. std::iterator_traits<UDT_iterator>::difference_type d = 0;
  28. std::iterator_traits<UDT_iterator>::pointer p = &v;
  29. std::iterator_traits<UDT_iterator>::reference r = v;
  30. std::iterator_traits<UDT_iterator>::iterator_category cat;
  31. std::iterator_traits<UDT*>::value_type v2;
  32. std::iterator_traits<UDT*>::difference_type d2 = 0;
  33. std::iterator_traits<UDT*>::pointer p2 = &v2;
  34. std::iterator_traits<UDT*>::reference r2 = v2;
  35. std::iterator_traits<UDT*>::iterator_category cat2;
  36. std::iterator_traits<const UDT*>::value_type v3;
  37. std::iterator_traits<const UDT*>::difference_type d3 = 0;
  38. std::iterator_traits<const UDT*>::pointer p3 = &v3;
  39. std::iterator_traits<const UDT*>::reference r3 = v3;
  40. std::iterator_traits<const UDT*>::iterator_category cat3;
  41. //
  42. // suppress some warnings:
  43. //
  44. (void) &v;
  45. (void) &d;
  46. (void) &p;
  47. (void) &r;
  48. (void) &cat;
  49. (void) &v2;
  50. (void) &d2;
  51. (void) &p2;
  52. (void) &r2;
  53. (void) &cat2;
  54. (void) &v3;
  55. (void) &d3;
  56. (void) &p3;
  57. (void) &r3;
  58. (void) &cat3;
  59. return 0;
  60. }
  61. }