SuperDex Physics C++ API
Loading...
Searching...
No Matches
array.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <cstddef>
20
23
24namespace superdex {
25
26template <typename T, size_t N>
27struct Array {
28 static_assert(N > 0, "Array size must be positive");
29 using value_type = T;
30 using size_type = size_t;
31
32 // clang-format off
33 [[nodiscard]] MOCHI_ANY MOCHI_FORCE_INLINE constexpr T& operator[](size_type i) { return v[i]; }
34 [[nodiscard]] MOCHI_ANY MOCHI_FORCE_INLINE constexpr T const& operator[](size_type i) const { return v[i]; }
35 [[nodiscard]] MOCHI_ANY MOCHI_FORCE_INLINE constexpr T& front() { return v[0]; }
36 [[nodiscard]] MOCHI_ANY MOCHI_FORCE_INLINE constexpr T const& front() const { return v[0]; }
37 [[nodiscard]] MOCHI_ANY MOCHI_FORCE_INLINE constexpr T& back() { return v[N - 1]; }
38 [[nodiscard]] MOCHI_ANY MOCHI_FORCE_INLINE constexpr T const& back() const { return v[N - 1]; }
39 [[nodiscard]] MOCHI_ANY MOCHI_FORCE_INLINE constexpr T* data() { return v; }
40 [[nodiscard]] MOCHI_ANY MOCHI_FORCE_INLINE constexpr T const* data() const { return v; }
41 [[nodiscard]] MOCHI_ANY MOCHI_FORCE_INLINE constexpr T* begin() { return v; }
42 [[nodiscard]] MOCHI_ANY MOCHI_FORCE_INLINE constexpr T const* begin() const { return v; }
43 [[nodiscard]] MOCHI_ANY MOCHI_FORCE_INLINE constexpr T* end() { return v + N; }
44 [[nodiscard]] MOCHI_ANY MOCHI_FORCE_INLINE constexpr T const* end() const { return v + N; }
45 [[nodiscard]] MOCHI_ANY MOCHI_FORCE_INLINE constexpr static size_type size() { return N; }
46 T v[N];
47 // clang-format on
48};
49
50} // namespace superdex
#define MOCHI_FORCE_INLINE
#define MOCHI_ANY
static constexpr size_type size()
Definition array.h:45
constexpr T & back()
Definition array.h:37
constexpr T const & back() const
Definition array.h:38
constexpr T const * data() const
Definition array.h:40
constexpr T & operator[](size_type i)
Definition array.h:33
constexpr T const * end() const
Definition array.h:44
constexpr T const & front() const
Definition array.h:36
constexpr T & front()
Definition array.h:35
constexpr T * data()
Definition array.h:39
constexpr T * end()
Definition array.h:43
constexpr T const & operator[](size_type i) const
Definition array.h:34
constexpr T * begin()
Definition array.h:41
constexpr T const * begin() const
Definition array.h:42