[X86] Pre-commit test for D157513
[llvm-project.git] / libcxx / include / __mdspan / default_accessor.h
blob1cc5f15545fc8cb8d50c8d74a896b89a955456e2
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).
12 // Under the terms of Contract DE-NA0003525 with NTESS,
13 // the U.S. Government retains certain rights in this software.
15 //===---------------------------------------------------------------------===//
17 #ifndef _LIBCPP___MDSPAN_DEFAULT_ACCESSOR_H
18 #define _LIBCPP___MDSPAN_DEFAULT_ACCESSOR_H
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>
28 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29 # pragma GCC system_header
30 #endif
32 _LIBCPP_PUSH_MACROS
33 #include <__undef_macros>
35 _LIBCPP_BEGIN_NAMESPACE_STD
37 #if _LIBCPP_STD_VER >= 23
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");
44 using offset_policy = default_accessor;
45 using element_type = _ElementType;
46 using reference = _ElementType&;
47 using data_handle_type = _ElementType*;
49 _LIBCPP_HIDE_FROM_ABI constexpr default_accessor() noexcept = default;
50 template <class _OtherElementType>
51 requires(is_convertible_v<_OtherElementType (*)[], element_type (*)[]>)
52 _LIBCPP_HIDE_FROM_ABI constexpr default_accessor(default_accessor<_OtherElementType>) noexcept {}
54 _LIBCPP_HIDE_FROM_ABI constexpr reference access(data_handle_type __p, size_t __i) const noexcept { return __p[__i]; }
55 _LIBCPP_HIDE_FROM_ABI constexpr data_handle_type offset(data_handle_type __p, size_t __i) const noexcept {
56 return __p + __i;
60 #endif // _LIBCPP_STD_VER >= 23
62 _LIBCPP_END_NAMESPACE_STD
64 _LIBCPP_POP_MACROS
66 #endif // _LIBCPP___MDSPAN_DEFAULT_ACCESSOR_H