EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_Array.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
14#ifndef EBGEOMETRY_ARRAY_HPP
15#define EBGEOMETRY_ARRAY_HPP
16
17#include <cstddef>
18
19#include "EBGeometry_GPU.hpp"
20
21namespace EBGeometry {
22
31template <class T, std::size_t N>
32struct Array
33{
34 static_assert(N > 0, "Array<T, N> requires N > 0");
35
39 T m_data[N];
40
46 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
47 constexpr T&
48 operator[](const std::size_t a_i) noexcept
49 {
50 return m_data[a_i];
51 }
52
58 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
59 constexpr const T&
60 operator[](const std::size_t a_i) const noexcept
61 {
62 return m_data[a_i];
63 }
64
69 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
70 static constexpr std::size_t
71 size() noexcept
72 {
73 return N;
74 }
75
80 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
81 constexpr T*
82 data() noexcept
83 {
84 return m_data;
85 }
86
91 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
92 constexpr const T*
93 data() const noexcept
94 {
95 return m_data;
96 }
97
102 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
103 constexpr T*
104 begin() noexcept
105 {
106 return m_data;
107 }
108
113 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
114 constexpr const T*
115 begin() const noexcept
116 {
117 return m_data;
118 }
119
124 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
125 constexpr T*
126 end() noexcept
127 {
128 return m_data + N;
129 }
130
135 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
136 constexpr const T*
137 end() const noexcept
138 {
139 return m_data + N;
140 }
141
147 constexpr void
148 fill(const T& a_value) noexcept
149 {
150 for (std::size_t i = 0; i < N; i++) {
151 m_data[i] = a_value;
152 }
153 }
154
160 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
161 constexpr bool
162 operator==(const Array& a_other) const noexcept
163 {
164 for (std::size_t i = 0; i < N; i++) {
165 if (!(m_data[i] == a_other.m_data[i])) {
166 return false;
167 }
168 }
169
170 return true;
171 }
172
178 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
179 constexpr bool
180 operator!=(const Array& a_other) const noexcept
181 {
182 return !(*this == a_other);
183 }
184};
185
186} // namespace EBGeometry
187
188#endif
GPU portability layer: host/device decoration macros and backend detection.
#define EBGEOMETRY_HOST_DEVICE
Mark a function as callable from both host and device code (no-op on host compilers).
Definition EBGeometry_GPU.hpp:80
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Fixed-size array with host- and device-callable members.
Definition EBGeometry_Array.hpp:33
constexpr bool operator==(const Array &a_other) const noexcept
Element-wise equality.
Definition EBGeometry_Array.hpp:162
constexpr T & operator[](const std::size_t a_i) noexcept
Element access.
Definition EBGeometry_Array.hpp:48
T m_data[N]
The elements. Public so that the type is an aggregate; use operator[] or data().
Definition EBGeometry_Array.hpp:39
constexpr const T & operator[](const std::size_t a_i) const noexcept
Element access.
Definition EBGeometry_Array.hpp:60
constexpr bool operator!=(const Array &a_other) const noexcept
Element-wise inequality.
Definition EBGeometry_Array.hpp:180
constexpr const T * begin() const noexcept
Iterator to the first element.
Definition EBGeometry_Array.hpp:115
constexpr const T * data() const noexcept
Pointer to the first element.
Definition EBGeometry_Array.hpp:93
constexpr T * end() noexcept
Iterator past the last element.
Definition EBGeometry_Array.hpp:126
constexpr T * begin() noexcept
Iterator to the first element.
Definition EBGeometry_Array.hpp:104
constexpr void fill(const T &a_value) noexcept
Set every element to a value.
Definition EBGeometry_Array.hpp:148
static constexpr std::size_t size() noexcept
Number of elements.
Definition EBGeometry_Array.hpp:71
constexpr const T * end() const noexcept
Iterator past the last element.
Definition EBGeometry_Array.hpp:137
constexpr T * data() noexcept
Pointer to the first element.
Definition EBGeometry_Array.hpp:82