Debian Codegraph @

Utilities/std/cmext/iterator

raw
1 // -*-c++-*-
2 // vim: set ft=cpp:
3
4 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
5 file LICENSE.rst or https://cmake.org/licensing for details. */
6 #pragma once
7
8 #include <iterator>
9
10 #include <cm/type_traits>
11
12 namespace cm {
13
14 // checks if a type is an iterator type
15 template <typename I>
16 using is_iterator =
17 std::is_integral<typename std::iterator_traits<I>::difference_type>;
18
19 // checks if a type is an input iterator type
20 template <typename I>
21 using is_input_iterator =
22 std::is_base_of<std::input_iterator_tag,
23 typename std::iterator_traits<I>::iterator_category>;
24
25 // checks if a type is a range type: std::begin() and std::end() are supported
26 template <typename Range>
27 using is_range =
28 #if defined(_MSC_VER) && _MSC_VER < 1920
29 // MS C++ is not able to evaluate complex type introspection,
30 // so use a simplified version
31 cm::bool_constant<std::is_class<Range>::value ||
32 std::is_array<Range>::value>;
33 #else
34 cm::bool_constant<
35 cm::is_iterator<decltype(std::begin(
36 std::declval<Range const>()))>::value &&
37 cm::is_iterator<decltype(std::end(std::declval<Range const>()))>::value>;
38 #endif
39
40 // checks if a type is an input range type: std::begin() and std::end() are
41 // returning an input iterator
42 template <typename Range>
43 using is_input_range =
44 #if defined(_MSC_VER) && _MSC_VER < 1920
45 // MS C++ is not able to evaluate complex type introspection,
46 // so use a simplified version
47 cm::bool_constant<std::is_class<Range>::value ||
48 std::is_pointer<Range>::value ||
49 std::is_array<Range>::value>;
50 #else
51 cm::bool_constant<cm::is_input_iterator<decltype(std::begin(
52 std::declval<Range const>()))>::value &&
53 cm::is_input_iterator<decltype(std::end(
54 std::declval<Range const>()))>::value>;
55 #endif
56
57 } // namespace cm