tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
default_accessor.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2023 Tobias Hienzsch
3
4#ifndef TETL_MDSPAN_DEFAULT_ACCESSOR_HPP
5#define TETL_MDSPAN_DEFAULT_ACCESSOR_HPP
6
7#include <etl/_cstddef/size_t.hpp>
8#include <etl/_type_traits/is_convertible.hpp>
9
10namespace etl {
11
12template <typename ElementType>
14 using offset_policy = default_accessor;
15 using element_type = ElementType;
16 using reference = ElementType&;
17 using data_handle_type = ElementType*;
18
19 constexpr default_accessor() noexcept = default;
20
21 template <typename OtherElementType>
22 requires is_convertible_v<OtherElementType (*)[], element_type (*)[]>
23 constexpr default_accessor(default_accessor<OtherElementType> /*unused*/) noexcept
24 {
25 }
26
27 [[nodiscard]] constexpr auto access(data_handle_type p, size_t i) const noexcept -> reference
28 {
29 return p[i];
30 }
31
32 [[nodiscard]] constexpr auto offset(data_handle_type p, size_t i) const noexcept -> data_handle_type
33 {
34 return p + i;
35 }
36};
37
38} // namespace etl
39
40#endif // TETL_MDSPAN_DEFAULT_ACCESSOR_HPP
Definition adjacent_find.hpp:9
Definition default_accessor.hpp:13
constexpr auto access(data_handle_type p, size_t i) const noexcept -> reference
Definition default_accessor.hpp:27
constexpr default_accessor() noexcept=default
constexpr default_accessor(default_accessor< OtherElementType >) noexcept
Definition default_accessor.hpp:23
constexpr auto offset(data_handle_type p, size_t i) const noexcept -> data_handle_type
Definition default_accessor.hpp:32