default_accessor.h 2.2 KB

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