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 <__type_traits/is_abstract.h> 22 #include <__type_traits/is_array.h> 23 #include <__type_traits/is_convertible.h> 24 #include <__type_traits/remove_const.h> 25 #include <cinttypes> 26 #include <cstddef> 27 28 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 29 # pragma GCC system_header 30 #endif 31 32 _LIBCPP_PUSH_MACROS 33 #include <__undef_macros> 34 35 _LIBCPP_BEGIN_NAMESPACE_STD 36 37 #if _LIBCPP_STD_VER >= 23 38 39 template <class _ElementType> 40 struct default_accessor { 41 static_assert(!is_array_v<_ElementType>, "default_accessor: template argument may not be an array type"); 42 static_assert(!is_abstract_v<_ElementType>, "default_accessor: template argument may not be an abstract class"); 43 44 using offset_policy = default_accessor; 45 using element_type = _ElementType; 46 using reference = _ElementType&; 47 using data_handle_type = _ElementType*; 48 49 _LIBCPP_HIDE_FROM_ABI constexpr default_accessor() noexcept = default; 50 template <class _OtherElementType> requiresdefault_accessor51 requires(is_convertible_v<_OtherElementType (*)[], element_type (*)[]>) 52 _LIBCPP_HIDE_FROM_ABI constexpr default_accessor(default_accessor<_OtherElementType>) noexcept {} 53 accessdefault_accessor54 _LIBCPP_HIDE_FROM_ABI constexpr reference access(data_handle_type __p, size_t __i) const noexcept { return __p[__i]; } offsetdefault_accessor55 _LIBCPP_HIDE_FROM_ABI constexpr data_handle_type offset(data_handle_type __p, size_t __i) const noexcept { 56 return __p + __i; 57 } 58 }; 59 60 #endif // _LIBCPP_STD_VER >= 23 61 62 _LIBCPP_END_NAMESPACE_STD 63 64 _LIBCPP_POP_MACROS 65 66 #endif // _LIBCPP___MDSPAN_DEFAULT_ACCESSOR_H 67