Loading...
Searching...
No Matches
default_accessor.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_COMMON_STD_DEFAULT_ACCESSOR_HH
#define DUNE_COMMON_STD_DEFAULT_ACCESSOR_HH
#include <type_traits>
namespace Dune::Std {
template <class Element>
class default_accessor
{
public:
using element_type = Element;
using data_handle_type = element_type*;
using reference = element_type&;
using offset_policy = default_accessor;
public:
// [mdspan.accessor.default.overview]
constexpr default_accessor () noexcept = default;
template <class OtherElement,
std::enable_if_t<std::is_convertible_v<OtherElement(*)[], Element(*)[]>, int> = 0>
constexpr default_accessor (default_accessor<OtherElement>) noexcept {}
constexpr reference access (data_handle_type p, std::size_t i) const noexcept
{
return p[i];
}
constexpr data_handle_type offset (data_handle_type p, std::size_t i) const noexcept
{
return p + i;
}
};
} // end namespace Dune::Std
#endif // DUNE_COMMON_STD_DEFAULT_ACCESSOR_HH
std
STL namespace.
Dune::Std
Namespace for features backported from new C++ standards.
Definition algorithm.hh:19
Dune::Std::default_accessor::data_handle_type
element_type * data_handle_type
Definition default_accessor.hh:27
Dune::Std::default_accessor::offset_policy
default_accessor offset_policy
Definition default_accessor.hh:29
Dune::Std::default_accessor::reference
element_type & reference
Definition default_accessor.hh:28
Dune::Std::default_accessor::element_type
Element element_type
Definition default_accessor.hh:26
Dune::Std::default_accessor::default_accessor
constexpr default_accessor() noexcept=default
Default constructor.
Dune::Std::default_accessor::access
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
Dune::Std::default_accessor::offset
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