Dune Core Modules (2.10.0)

default_accessor.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_COMMON_STD_DEFAULT_ACCESSOR_HH
6#define DUNE_COMMON_STD_DEFAULT_ACCESSOR_HH
7
8#include <type_traits>
9
10namespace Dune::Std {
11
22template <class Element>
24{
25public:
26 using element_type = Element;
27 using data_handle_type = element_type*;
28 using reference = element_type&;
30
31public:
32 // [mdspan.accessor.default.overview]
34 constexpr default_accessor () noexcept = default;
35
37 template <class OtherElement,
38 std::enable_if_t<std::is_convertible_v<OtherElement(*)[], Element(*)[]>, int> = 0>
39 constexpr default_accessor (default_accessor<OtherElement>) noexcept {}
40
42 constexpr reference access (data_handle_type p, std::size_t i) const noexcept
43 {
44 return p[i];
45 }
46
48 constexpr data_handle_type offset (data_handle_type p, std::size_t i) const noexcept
49 {
50 return p + i;
51 }
52};
53
54} // end namespace Dune::Std
55
56#endif // DUNE_COMMON_STD_DEFAULT_ACCESSOR_HH
A type for indexed access to elements of mdspan.
Definition: default_accessor.hh:24
constexpr default_accessor() noexcept=default
Default constructor.
constexpr reference access(data_handle_type p, std::size_t i) const noexcept
Return a reference to the i'th element in the data range starting at p
Definition: default_accessor.hh:42
constexpr data_handle_type offset(data_handle_type p, std::size_t i) const noexcept
Return a data handle to the i'th element in the data range starting at p
Definition: default_accessor.hh:48
Namespace for features backported from new C++ standards.
Definition: default_accessor.hh:10
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 27, 23:30, 2024)