TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
accessors.hpp
Go to the documentation of this file.
1// Copyright (c) 2019--present, The Simons Foundation
2// This file is part of TRIQS/nda and is licensed under the Apache License, Version 2.0.
3// SPDX-License-Identifier: Apache-2.0
4// See LICENSE in the root of this distribution for details.
5
10
11#pragma once
12
13#include "./macros.hpp"
14
15#include <cstddef>
16
17namespace nda {
18
23
30 template <typename T>
31 struct accessor {
33 using element_type = T;
34
36 using pointer = T *;
37
39 using reference = T &;
40
48 FORCEINLINE static reference access(pointer p, std::ptrdiff_t i) noexcept {
49 EXPECTS(p != nullptr);
50 return p[i];
51 }
52
60 FORCEINLINE static T *offset(pointer p, std::ptrdiff_t i) noexcept { return p + i; }
61 };
62 };
63
70 template <typename T>
71 struct accessor {
73 using element_type = T;
74
76 using pointer = T *__restrict;
77
79 using reference = T &;
80
88 FORCEINLINE static reference access(pointer p, std::ptrdiff_t i) noexcept { return p[i]; }
89
97 FORCEINLINE static T *offset(pointer p, std::ptrdiff_t i) noexcept { return p + i; }
98 };
99 };
100
102
103} // namespace nda
Macros used in the nda library.
Accessor type of the nda::default_accessor.
Definition accessors.hpp:31
static __inline__ T * offset(pointer p, std::ptrdiff_t i) noexcept
Offset the pointer by a certain number of elements.
Definition accessors.hpp:60
T * pointer
Pointer type to the data.
Definition accessors.hpp:36
T element_type
Value type of the data.
Definition accessors.hpp:33
T & reference
Reference type to the data.
Definition accessors.hpp:39
static __inline__ reference access(pointer p, std::ptrdiff_t i) noexcept
Access a specific element of the data.
Definition accessors.hpp:48
Default accessor for various array and view types.
Definition accessors.hpp:25
Accessor type of the nda::no_alias_accessor.
Definition accessors.hpp:71
static __inline__ reference access(pointer p, std::ptrdiff_t i) noexcept
Access a specific element of the data.
Definition accessors.hpp:88
T & reference
Reference type to the data.
Definition accessors.hpp:79
T element_type
Value type of the data.
Definition accessors.hpp:73
static __inline__ T * offset(pointer p, std::ptrdiff_t i) noexcept
Offset the pointer by a certain number of elements.
Definition accessors.hpp:97
T *__restrict pointer
Restricted pointer type to the data.
Definition accessors.hpp:76
Accessor for array and view types with no aliasing.
Definition accessors.hpp:65