• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
6//  See http://www.boost.org/libs/config for most recent version.
7
8//  MACRO:         BOOST_NO_CXX17_ITERATOR_TRAITS
9//  TITLE:         C++17 std::iterator_traits
10//  DESCRIPTION:   The compiler does not support SFINAE-friendly std::iterator_traits defined in C++17.
11
12#include <iterator>
13
14namespace boost_no_cxx17_iterator_traits {
15
16struct iterator
17{
18   typedef std::random_access_iterator_tag iterator_category;
19   typedef char value_type;
20   typedef std::ptrdiff_t difference_type;
21   typedef char* pointer;
22   typedef char& reference;
23
24   reference operator*()const;
25   iterator operator++();
26};
27
28struct non_iterator {};
29
30template< typename T >
31struct void_type { typedef void type; };
32
33template< typename Traits, typename Void = void >
34struct has_iterator_category
35{
36    enum { value = false };
37};
38
39template< typename Traits >
40struct has_iterator_category< Traits, typename void_type< typename Traits::iterator_category >::type >
41{
42    enum { value = true };
43};
44
45int test()
46{
47    static_assert(has_iterator_category< std::iterator_traits< boost_no_cxx17_iterator_traits::iterator > >::value, "has_iterator_category failed");
48
49    static_assert(!has_iterator_category< std::iterator_traits< boost_no_cxx17_iterator_traits::non_iterator > >::value, "has_iterator_category negative check failed");
50
51    return 0;
52}
53
54}
55