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-2020 Simons Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0.txt
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Olivier Parcollet, Nils Wentzell
16
22#pragma once
23
24#include "./macros.hpp"
25
26#include <cstddef>
27
28namespace nda {
29
41 template <typename T>
42 struct accessor {
44 using element_type = T;
45
47 using pointer = T *;
48
50 using reference = T &;
51
59 FORCEINLINE static reference access(pointer p, std::ptrdiff_t i) noexcept {
60 EXPECTS(p != nullptr);
61 return p[i];
62 }
63
71 FORCEINLINE static T *offset(pointer p, std::ptrdiff_t i) noexcept { return p + i; }
72 };
73 };
74
81 template <typename T>
82 struct accessor {
84 using element_type = T;
85
87 using pointer = T *__restrict;
88
90 using reference = T &;
91
99 FORCEINLINE static reference access(pointer p, std::ptrdiff_t i) noexcept { return p[i]; }
100
108 FORCEINLINE static T *offset(pointer p, std::ptrdiff_t i) noexcept { return p + i; }
109 };
110 };
111
114} // namespace nda
Macros used in the nda library.
Accessor type of the nda::default_accessor.
Definition accessors.hpp:42
static __inline__ T * offset(pointer p, std::ptrdiff_t i) noexcept
Offset the pointer by a certain number of elements.
Definition accessors.hpp:71
T * pointer
Pointer type to the data.
Definition accessors.hpp:47
T element_type
Value type of the data.
Definition accessors.hpp:44
T & reference
Reference type to the data.
Definition accessors.hpp:50
static __inline__ reference access(pointer p, std::ptrdiff_t i) noexcept
Access a specific element of the data.
Definition accessors.hpp:59
Default accessor for various array and view types.
Definition accessors.hpp:36
Accessor type of the nda::no_alias_accessor.
Definition accessors.hpp:82
static __inline__ reference access(pointer p, std::ptrdiff_t i) noexcept
Access a specific element of the data.
Definition accessors.hpp:99
T & reference
Reference type to the data.
Definition accessors.hpp:90
T element_type
Value type of the data.
Definition accessors.hpp:84
static __inline__ T * offset(pointer p, std::ptrdiff_t i) noexcept
Offset the pointer by a certain number of elements.
T *__restrict pointer
Restricted pointer type to the data.
Definition accessors.hpp:87
Accessor for array and view types with no aliasing.
Definition accessors.hpp:76