tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
iterator_traits.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2020 Tobias Hienzsch
3
4#ifndef TETL_ITERATOR_ITERATOR_TRAITS_HPP
5#define TETL_ITERATOR_ITERATOR_TRAITS_HPP
6
7#include <etl/_cstddef/ptrdiff_t.hpp>
8#include <etl/_iterator/tags.hpp>
9#include <etl/_type_traits/remove_cv.hpp>
10#include <etl/_type_traits/void_t.hpp>
11
12namespace etl {
13
14namespace detail {
15template <typename Iter, typename = etl::void_t<>>
16struct iterator_traits_impl { };
17
18template <typename Iter>
19struct iterator_traits_impl<
20 Iter,
21 etl::void_t< //
22 typename Iter::iterator_category, //
23 typename Iter::value_type, //
24 typename Iter::difference_type, //
25 typename Iter::pointer, //
26 typename Iter::reference //
27 > //
28 > {
29 using iterator_category = typename Iter::iterator_category;
30 using value_type = typename Iter::value_type;
31 using difference_type = typename Iter::difference_type;
32 using pointer = typename Iter::pointer;
33 using reference = typename Iter::reference;
34};
35
36} // namespace detail
37
38/// \brief iterator_traits is the type trait class that provides uniform
39/// interface to the properties of LegacyIterator types. This makes it possible
40/// to implement algorithms only in terms of iterators.
41///
42/// \details The template can be specialized for user-defined iterators so that
43/// the information about the iterator can be retrieved even if the type does
44/// not provide the usual typedefs.
45///
46/// https://en.cppreference.com/w/cpp/iterator/iterator_traits
47template <typename Iter>
48struct iterator_traits : detail::iterator_traits_impl<Iter> { };
49
50template <typename T>
51struct iterator_traits<T*> {
52 using iterator_concept = contiguous_iterator_tag;
53 using iterator_category = random_access_iterator_tag;
54 using value_type = remove_cv_t<T>;
55 using difference_type = ptrdiff_t;
56 using pointer = T*;
57 using reference = T&;
58};
59
60} // namespace etl
61
62#endif // TETL_ITERATOR_ITERATOR_TRAITS_HPP
Definition adjacent_find.hpp:9
Defines the category of an iterator. Each tag is an empty type and corresponds to one of the five (un...
Definition tags.hpp:43
iterator_traits is the type trait class that provides uniform interface to the properties of LegacyIt...
Definition iterator_traits.hpp:48
Defines the category of an iterator. Each tag is an empty type and corresponds to one of the five (un...
Definition tags.hpp:37