boost_no_cxx17_iterator_traits.ipp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) Andrey Semashev 2017.
  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 most recent version.
  6. // MACRO: BOOST_NO_CXX17_ITERATOR_TRAITS
  7. // TITLE: C++17 std::iterator_traits
  8. // DESCRIPTION: The compiler does not support SFINAE-friendly std::iterator_traits defined in C++17.
  9. #include <iterator>
  10. namespace boost_no_cxx17_iterator_traits {
  11. struct iterator
  12. {
  13. typedef std::random_access_iterator_tag iterator_category;
  14. typedef char value_type;
  15. typedef std::ptrdiff_t difference_type;
  16. typedef char* pointer;
  17. typedef char& reference;
  18. reference operator*()const;
  19. iterator operator++();
  20. };
  21. struct non_iterator {};
  22. template< typename T >
  23. struct void_type { typedef void type; };
  24. template< typename Traits, typename Void = void >
  25. struct has_iterator_category
  26. {
  27. enum { value = false };
  28. };
  29. template< typename Traits >
  30. struct has_iterator_category< Traits, typename void_type< typename Traits::iterator_category >::type >
  31. {
  32. enum { value = true };
  33. };
  34. int test()
  35. {
  36. static_assert(has_iterator_category< std::iterator_traits< boost_no_cxx17_iterator_traits::iterator > >::value, "has_iterator_category failed");
  37. static_assert(!has_iterator_category< std::iterator_traits< boost_no_cxx17_iterator_traits::non_iterator > >::value, "has_iterator_category negative check failed");
  38. return 0;
  39. }
  40. }