tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
emulation.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_CONCEPTS_EMULATION_HPP
5#define TETL_CONCEPTS_EMULATION_HPP
6
7#include <etl/_iterator/begin.hpp>
8#include <etl/_iterator/end.hpp>
9#include <etl/_iterator/iterator_traits.hpp>
10#include <etl/_type_traits/bool_constant.hpp>
11#include <etl/_type_traits/declval.hpp>
12#include <etl/_type_traits/is_assignable.hpp>
13#include <etl/_type_traits/is_convertible.hpp>
14#include <etl/_type_traits/is_move_constructible.hpp>
15#include <etl/_type_traits/is_object.hpp>
16#include <etl/_type_traits/is_swappable.hpp>
17#include <etl/_type_traits/void_t.hpp>
18
19namespace etl::detail {
20
21// Concepts (poor-man emulation using type traits)
22/// Copied from https://github.com/gnzlbg/static_vector
23
24template <typename T>
25inline constexpr bool is_movable_v
26 = is_object_v<T> and is_assignable_v<T&, T> and is_move_constructible_v<T> and is_swappable_v<T&>;
27
28template <typename Rng>
29using range_iterator_t = decltype(etl::begin(etl::declval<Rng>()));
30
31template <typename T>
32using iterator_reference_t = typename iterator_traits<T>::reference;
33
34template <typename T>
35using iterator_category_t = typename iterator_traits<T>::iterator_category;
36
37template <typename T, typename Category, typename = void>
38struct IteratorConcept : false_type { };
39
40template <typename T, typename Category>
41struct IteratorConcept<T, Category, void_t<iterator_category_t<T>>>
42 : bool_constant<is_convertible_v<iterator_category_t<T>, Category>> { };
43
44// clang-format off
45template <typename T> inline constexpr bool InputIterator = IteratorConcept<T, input_iterator_tag> {};
46template <typename T> inline constexpr bool ForwardIterator = IteratorConcept<T, forward_iterator_tag> {};
47template <typename T> inline constexpr bool OutputIterator = IteratorConcept<T, output_iterator_tag> {} || ForwardIterator<T>;
48template <typename T> inline constexpr bool BidirectionalIterator = IteratorConcept<T, bidirectional_iterator_tag> {};
49template <typename T> inline constexpr bool RandomAccessIterator = IteratorConcept<T, random_access_iterator_tag> {};
50template <typename T> inline constexpr bool RandomAccessRange = RandomAccessIterator<range_iterator_t<T>>;
51// clang-format on
52
53} // namespace etl::detail
54
55#endif // TETL_CONCEPTS_EMULATION_HPP
Definition adjacent_find.hpp:9
iterator_traits is the type trait class that provides uniform interface to the properties of LegacyIt...
Definition iterator_traits.hpp:48