xref: /freebsd/contrib/llvm-project/libcxx/include/__mdspan/default_accessor.h (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1*06c3fb27SDimitry Andric // -*- C++ -*-
2*06c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
3*06c3fb27SDimitry Andric //
4*06c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*06c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6*06c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*06c3fb27SDimitry Andric //
8*06c3fb27SDimitry Andric //                        Kokkos v. 4.0
9*06c3fb27SDimitry Andric //       Copyright (2022) National Technology & Engineering
10*06c3fb27SDimitry Andric //               Solutions of Sandia, LLC (NTESS).
11*06c3fb27SDimitry Andric //
12*06c3fb27SDimitry Andric // Under the terms of Contract DE-NA0003525 with NTESS,
13*06c3fb27SDimitry Andric // the U.S. Government retains certain rights in this software.
14*06c3fb27SDimitry Andric //
15*06c3fb27SDimitry Andric //===---------------------------------------------------------------------===//
16*06c3fb27SDimitry Andric 
17*06c3fb27SDimitry Andric #ifndef _LIBCPP___MDSPAN_DEFAULT_ACCESSOR_H
18*06c3fb27SDimitry Andric #define _LIBCPP___MDSPAN_DEFAULT_ACCESSOR_H
19*06c3fb27SDimitry Andric 
20*06c3fb27SDimitry Andric #include <__config>
21*06c3fb27SDimitry Andric #include <__type_traits/is_abstract.h>
22*06c3fb27SDimitry Andric #include <__type_traits/is_array.h>
23*06c3fb27SDimitry Andric #include <__type_traits/is_convertible.h>
24*06c3fb27SDimitry Andric #include <__type_traits/remove_const.h>
25*06c3fb27SDimitry Andric #include <cinttypes>
26*06c3fb27SDimitry Andric #include <cstddef>
27*06c3fb27SDimitry Andric 
28*06c3fb27SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29*06c3fb27SDimitry Andric #  pragma GCC system_header
30*06c3fb27SDimitry Andric #endif
31*06c3fb27SDimitry Andric 
32*06c3fb27SDimitry Andric _LIBCPP_PUSH_MACROS
33*06c3fb27SDimitry Andric #include <__undef_macros>
34*06c3fb27SDimitry Andric 
35*06c3fb27SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
36*06c3fb27SDimitry Andric 
37*06c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 23
38*06c3fb27SDimitry Andric 
39*06c3fb27SDimitry Andric template <class _ElementType>
40*06c3fb27SDimitry Andric struct default_accessor {
41*06c3fb27SDimitry Andric   static_assert(!is_array_v<_ElementType>, "default_accessor: template argument may not be an array type");
42*06c3fb27SDimitry Andric   static_assert(!is_abstract_v<_ElementType>, "default_accessor: template argument may not be an abstract class");
43*06c3fb27SDimitry Andric 
44*06c3fb27SDimitry Andric   using offset_policy    = default_accessor;
45*06c3fb27SDimitry Andric   using element_type     = _ElementType;
46*06c3fb27SDimitry Andric   using reference        = _ElementType&;
47*06c3fb27SDimitry Andric   using data_handle_type = _ElementType*;
48*06c3fb27SDimitry Andric 
49*06c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI constexpr default_accessor() noexcept = default;
50*06c3fb27SDimitry Andric   template <class _OtherElementType>
requiresdefault_accessor51*06c3fb27SDimitry Andric     requires(is_convertible_v<_OtherElementType (*)[], element_type (*)[]>)
52*06c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI constexpr default_accessor(default_accessor<_OtherElementType>) noexcept {}
53*06c3fb27SDimitry Andric 
accessdefault_accessor54*06c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI constexpr reference access(data_handle_type __p, size_t __i) const noexcept { return __p[__i]; }
offsetdefault_accessor55*06c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI constexpr data_handle_type offset(data_handle_type __p, size_t __i) const noexcept {
56*06c3fb27SDimitry Andric     return __p + __i;
57*06c3fb27SDimitry Andric   }
58*06c3fb27SDimitry Andric };
59*06c3fb27SDimitry Andric 
60*06c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 23
61*06c3fb27SDimitry Andric 
62*06c3fb27SDimitry Andric _LIBCPP_END_NAMESPACE_STD
63*06c3fb27SDimitry Andric 
64*06c3fb27SDimitry Andric _LIBCPP_POP_MACROS
65*06c3fb27SDimitry Andric 
66*06c3fb27SDimitry Andric #endif // _LIBCPP___MDSPAN_DEFAULT_ACCESSOR_H
67