Path: blob/main/contrib/llvm-project/libcxx/include/__mdspan/aligned_accessor.h
213766 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7// Kokkos v. 4.08// Copyright (2022) National Technology & Engineering9// Solutions of Sandia, LLC (NTESS).10//11// Under the terms of Contract DE-NA0003525 with NTESS,12// the U.S. Government retains certain rights in this software.13//14//===---------------------------------------------------------------------===//1516#ifndef _LIBCPP___MDSPAN_ALIGNED_ACCESSOR_H17#define _LIBCPP___MDSPAN_ALIGNED_ACCESSOR_H1819#include <__config>20#include <__cstddef/size_t.h>21#include <__mdspan/default_accessor.h>22#include <__memory/assume_aligned.h>23#include <__type_traits/is_abstract.h>24#include <__type_traits/is_array.h>25#include <__type_traits/is_convertible.h>26#include <__type_traits/remove_const.h>2728#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)29# pragma GCC system_header30#endif3132_LIBCPP_PUSH_MACROS33#include <__undef_macros>3435_LIBCPP_BEGIN_NAMESPACE_STD3637#if _LIBCPP_STD_VER >= 263839template <class _ElementType, size_t _ByteAlignment>40struct aligned_accessor {41static_assert(_ByteAlignment != 0 && (_ByteAlignment & (_ByteAlignment - 1)) == 0,42"aligned_accessor: byte alignment must be a power of two");43static_assert(_ByteAlignment >= alignof(_ElementType), "aligned_accessor: insufficient byte alignment");44static_assert(!is_array_v<_ElementType>, "aligned_accessor: template argument may not be an array type");45static_assert(!is_abstract_v<_ElementType>, "aligned_accessor: template argument may not be an abstract class");4647using offset_policy = default_accessor<_ElementType>;48using element_type = _ElementType;49using reference = _ElementType&;50using data_handle_type = _ElementType*;5152static constexpr size_t byte_alignment = _ByteAlignment;5354_LIBCPP_HIDE_FROM_ABI constexpr aligned_accessor() noexcept = default;5556template <class _OtherElementType, size_t _OtherByteAlignment>57requires(is_convertible_v<_OtherElementType (*)[], element_type (*)[]> && _OtherByteAlignment >= byte_alignment)58_LIBCPP_HIDE_FROM_ABI constexpr aligned_accessor(aligned_accessor<_OtherElementType, _OtherByteAlignment>) noexcept {}5960template <class _OtherElementType>61requires(is_convertible_v<_OtherElementType (*)[], element_type (*)[]>)62_LIBCPP_HIDE_FROM_ABI explicit constexpr aligned_accessor(default_accessor<_OtherElementType>) noexcept {}6364template <class _OtherElementType>65requires(is_convertible_v<element_type (*)[], _OtherElementType (*)[]>)66_LIBCPP_HIDE_FROM_ABI constexpr operator default_accessor<_OtherElementType>() const noexcept {67return {};68}6970_LIBCPP_HIDE_FROM_ABI constexpr reference access(data_handle_type __p, size_t __i) const noexcept {71return std::assume_aligned<byte_alignment>(__p)[__i];72}7374_LIBCPP_HIDE_FROM_ABI constexpr typename offset_policy::data_handle_type75offset(data_handle_type __p, size_t __i) const noexcept {76return std::assume_aligned<byte_alignment>(__p) + __i;77}78};7980#endif // _LIBCPP_STD_VER >= 268182_LIBCPP_END_NAMESPACE_STD8384_LIBCPP_POP_MACROS8586#endif // _LIBCPP___MDSPAN_ALIGNED_ACCESSOR_H878889