dune-common  2.11
default_accessor.hh
Go to the documentation of this file.
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 
10 namespace Dune::Std {
11 
22 template <class Element>
24 {
25 public:
26  using element_type = Element;
30 
31 public:
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
Namespace for features backported from new C++ standards.
Definition: algorithm.hh:19
constexpr data_handle_type offset(data_handle_type p, std::size_t i) const noexcept
Return a data handle to the i&#39;th element in the data range starting at p
Definition: default_accessor.hh:48
constexpr default_accessor() noexcept=default
Default constructor.
Element element_type
Definition: default_accessor.hh:26
element_type * data_handle_type
Definition: default_accessor.hh:27
I i
Definition: hybridmultiindex.hh:328
A type for indexed access to elements of mdspan.The default_accessor class template is the default Ac...
Definition: default_accessor.hh:23
element_type & reference
Definition: default_accessor.hh:28
STL namespace.
constexpr reference access(data_handle_type p, std::size_t i) const noexcept
Return a reference to the i&#39;th element in the data range starting at p
Definition: default_accessor.hh:42