WPILibC++
2025.2.1
Loading...
Searching...
No Matches
array.h
Go to the documentation of this file.
1
// Copyright (c) FIRST and other WPILib contributors.
2
// Open Source Software; you can modify and/or share it under the terms of
3
// the WPILib BSD license file in the root directory of this project.
4
5
#pragma once
6
7
#include <array>
8
#include <concepts>
9
#include <cstddef>
10
#include <tuple>
11
#include <utility>
12
13
namespace
wpi
{
14
15
struct
empty_array_t
{};
16
constexpr
empty_array_t
empty_array
;
17
18
/**
19
* This class is a wrapper around std::array that does compile time size
20
* checking.
21
*
22
* std::array's implicit constructor can result in uninitialized elements if the
23
* number of arguments doesn't match the std::array size.
24
*/
25
template
<
typename
T,
size_t
N>
26
class
array
:
public
std::array<T, N> {
27
public
:
28
constexpr
explicit
array
(
empty_array_t
) {}
29
30
template
<std::convertible_to<T>... Ts>
31
requires
(1 +
sizeof
...(Ts) == N)
32
constexpr
array
(T
arg
, Ts&&... args)
// NOLINT
33
: std::array<T, N>{std::forward<T>(
arg
), std::forward<Ts>(args)...} {}
34
35
constexpr
array
(
const
array<T, N>
&) =
default
;
36
constexpr
array
&
operator=
(
const
array<T, N>
&) =
default
;
37
constexpr
array
(
array<T, N>
&&) =
default
;
38
constexpr
array
&
operator=
(
array<T, N>
&&) =
default
;
39
40
constexpr
array
(
const
std::array<T, N>& rhs) {
// NOLINT
41
*
static_cast<
std::array<T, N>*
>
(
this
) = rhs;
42
}
43
44
constexpr
array
&
operator=
(
const
std::array<T, N>& rhs) {
45
*
static_cast<
std::array<T, N>*
>
(
this
) = rhs;
46
return
*
this
;
47
}
48
49
constexpr
array
(std::array<T, N>&& rhs) {
// NOLINT
50
*
static_cast<
std::array<T, N>*
>
(
this
) = rhs;
51
}
52
53
constexpr
array
&
operator=
(std::array<T, N>&& rhs) {
54
*
static_cast<
std::array<T, N>*
>
(
this
) = rhs;
55
return
*
this
;
56
}
57
};
58
59
template
<
typename
T, std::convertible_to<T>... Ts>
60
array
(T, Ts...) ->
array
<T, 1 +
sizeof
...(Ts)>;
61
62
}
// namespace wpi
63
64
template
<
size_t
I,
typename
T,
size_t
N>
65
requires
(I < N)
66
constexpr
T&
get
(
wpi::array<T, N>
& arr)
noexcept
{
67
return
std::get<I>(
static_cast<
std::array<T, N>
>
(arr));
68
}
69
70
template
<
size_t
I,
typename
T,
size_t
N>
71
requires
(I < N)
72
constexpr
T&&
get
(
wpi::array<T, N>
&& arr)
noexcept
{
73
return
std::move(std::get<I>(arr));
74
}
75
76
template
<
size_t
I,
typename
T,
size_t
N>
77
requires
(I < N)
78
constexpr
const
T&
get
(
const
wpi::array<T, N>
& arr)
noexcept
{
79
return
std::get<I>(
static_cast<
std::array<T, N>
>
(arr));
80
}
81
82
template
<
size_t
I,
typename
T,
size_t
N>
83
requires
(I < N)
84
constexpr
const
T&&
get
(
const
wpi::array<T, N>
&& arr)
noexcept
{
85
return
std::move(std::get<I>(arr));
86
}
87
88
// Enables structured bindings
89
namespace
std
{
// NOLINT
90
// Partial specialization for wpi::array
91
template
<
typename
T,
size_t
N>
92
struct
tuple_size<
wpi
::array<T, N>> :
public
integral_constant<size_t, N> {};
93
94
// Partial specialization for wpi::array
95
template
<
size_t
I,
typename
T,
size_t
N>
96
requires
(I < N)
97
struct
tuple_element<I,
wpi::array<T, N>
> {
98
using
type
= T;
99
};
100
}
// namespace std
get
constexpr T & get(wpi::array< T, N > &arr) noexcept
Definition
array.h:66
wpi::array
This class is a wrapper around std::array that does compile time size checking.
Definition
array.h:26
wpi::array::operator=
constexpr array & operator=(std::array< T, N > &&rhs)
Definition
array.h:53
wpi::array::operator=
constexpr array & operator=(const std::array< T, N > &rhs)
Definition
array.h:44
wpi::array::operator=
constexpr array & operator=(const array< T, N > &)=default
wpi::array::array
constexpr array(const std::array< T, N > &rhs)
Definition
array.h:40
wpi::array::array
constexpr array(std::array< T, N > &&rhs)
Definition
array.h:49
wpi::array::array
constexpr array(const array< T, N > &)=default
wpi::array::array
constexpr array(array< T, N > &&)=default
wpi::array::operator=
constexpr array & operator=(array< T, N > &&)=default
wpi::array::array
constexpr array(empty_array_t)
Definition
array.h:28
wpi::array::array
constexpr array(T arg, Ts &&... args)
Definition
array.h:32
std
Implement std::hash so that hash_code can be used in STL containers.
Definition
PointerIntPair.h:280
wpi
Foonathan namespace.
Definition
ntcore_cpp.h:26
wpi::array
array(T, Ts...) -> array< T, 1+sizeof...(Ts)>
wpi::empty_array
constexpr empty_array_t empty_array
Definition
array.h:16
std::tuple_element< I, wpi::array< T, N > >::type
T type
Definition
array.h:98
wpi::empty_array_t
Definition
array.h:15
arg
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Returns a named argument to be used in a formatting function.
Definition
base.h:2775
wpi
array.h
Generated on Fri Jan 10 2025 07:37:20 for WPILibC++ by
1.12.0