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
3#ifndef TETL_CONCEPTS_EMULATION_HPP
4#define TETL_CONCEPTS_EMULATION_HPP
5
17
18namespace etl::detail {
19
20// Concepts (poor-man emulation using type traits)
22
23template <typename T>
24inline constexpr bool is_movable_v
26
27template <typename Rng>
28using range_iterator_t = decltype(etl::begin(etl::declval<Rng>()));
29
30template <typename T>
31using iterator_reference_t = typename iterator_traits<T>::reference;
32
33template <typename T>
34using iterator_category_t = typename iterator_traits<T>::iterator_category;
35
36template <typename T, typename Category, typename = void>
37struct IteratorConcept : false_type { };
38
39template <typename T, typename Category>
40struct IteratorConcept<T, Category, void_t<iterator_category_t<T>>>
41 : bool_constant<is_convertible_v<iterator_category_t<T>, Category>> { };
42
43// clang-format off
44template <typename T> inline constexpr bool InputIterator = IteratorConcept<T, input_iterator_tag> {};
45template <typename T> inline constexpr bool ForwardIterator = IteratorConcept<T, forward_iterator_tag> {};
46template <typename T> inline constexpr bool OutputIterator = IteratorConcept<T, output_iterator_tag> {} || ForwardIterator<T>;
47template <typename T> inline constexpr bool BidirectionalIterator = IteratorConcept<T, bidirectional_iterator_tag> {};
48template <typename T> inline constexpr bool RandomAccessIterator = IteratorConcept<T, random_access_iterator_tag> {};
49template <typename T> inline constexpr bool RandomAccessRange = RandomAccessIterator<range_iterator_t<T>>;
50// clang-format on
51
52} // namespace etl::detail
53
54#endif // TETL_CONCEPTS_EMULATION_HPP
constexpr auto begin(C &c) -> decltype(c.begin())
Returns an iterator to the beginning of the given container c or array array. These templates rely on...
Definition begin.hpp:20
void void_t
Definition void_t.hpp:10
auto declval() noexcept -> add_rvalue_reference_t< T >
constexpr bool is_move_constructible_v
Definition is_move_constructible.hpp:20
constexpr bool is_swappable_v
Definition is_swappable.hpp:21
constexpr bool is_object_v
Definition is_object.hpp:35
constexpr bool is_assignable_v
Definition is_assignable.hpp:20
integral_constant< bool, B > bool_constant
Definition bool_constant.hpp:11
bool_constant< false > false_type
Definition bool_constant.hpp:14