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