mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[wpiutil] Make wpi::array constexpr (#4278)
This commit is contained in:
@@ -24,33 +24,33 @@ constexpr empty_array_t empty_array;
|
||||
template <typename T, size_t N>
|
||||
class array : public std::array<T, N> {
|
||||
public:
|
||||
explicit array(empty_array_t) {}
|
||||
constexpr explicit array(empty_array_t) {}
|
||||
|
||||
template <typename... Ts>
|
||||
array(T arg, Ts&&... args) // NOLINT
|
||||
constexpr array(T arg, Ts&&... args) // NOLINT
|
||||
: std::array<T, N>{std::forward<T>(arg), std::forward<Ts>(args)...} {
|
||||
static_assert(1 + sizeof...(args) == N, "Dimension mismatch");
|
||||
}
|
||||
|
||||
array(const array<T, N>&) = default;
|
||||
array& operator=(const array<T, N>&) = default;
|
||||
array(array<T, N>&&) = default;
|
||||
array& operator=(array<T, N>&&) = default;
|
||||
constexpr array(const array<T, N>&) = default;
|
||||
constexpr array& operator=(const array<T, N>&) = default;
|
||||
constexpr array(array<T, N>&&) = default;
|
||||
constexpr array& operator=(array<T, N>&&) = default;
|
||||
|
||||
array(const std::array<T, N>& rhs) { // NOLINT
|
||||
constexpr array(const std::array<T, N>& rhs) { // NOLINT
|
||||
*static_cast<std::array<T, N>*>(this) = rhs;
|
||||
}
|
||||
|
||||
array& operator=(const std::array<T, N>& rhs) {
|
||||
constexpr array& operator=(const std::array<T, N>& rhs) {
|
||||
*static_cast<std::array<T, N>*>(this) = rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
array(std::array<T, N>&& rhs) { // NOLINT
|
||||
constexpr array(std::array<T, N>&& rhs) { // NOLINT
|
||||
*static_cast<std::array<T, N>*>(this) = rhs;
|
||||
}
|
||||
|
||||
array& operator=(std::array<T, N>&& rhs) {
|
||||
constexpr array& operator=(std::array<T, N>&& rhs) {
|
||||
*static_cast<std::array<T, N>*>(this) = rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -15,16 +15,20 @@ class MoveOnlyType {
|
||||
} // namespace
|
||||
|
||||
TEST(ArrayTest, CopyableTypeCompiles) {
|
||||
wpi::array<int, 3> arr1{1, 2, 3};
|
||||
constexpr wpi::array<int, 3> arr1{1, 2, 3};
|
||||
static_cast<void>(arr1);
|
||||
|
||||
// Test deduction guide
|
||||
wpi::array ar2{1, 2, 3};
|
||||
constexpr wpi::array arr2{1, 2, 3};
|
||||
static_cast<void>(arr2);
|
||||
}
|
||||
|
||||
TEST(ArrayTest, MoveOnlyTypeCompiles) {
|
||||
wpi::array<MoveOnlyType, 3> arr1{MoveOnlyType{}, MoveOnlyType{},
|
||||
MoveOnlyType{}};
|
||||
constexpr wpi::array<MoveOnlyType, 3> arr1{MoveOnlyType{}, MoveOnlyType{},
|
||||
MoveOnlyType{}};
|
||||
static_cast<void>(arr1);
|
||||
|
||||
// Test deduction guide
|
||||
wpi::array arr2{MoveOnlyType{}, MoveOnlyType{}, MoveOnlyType{}};
|
||||
constexpr wpi::array arr2{MoveOnlyType{}, MoveOnlyType{}, MoveOnlyType{}};
|
||||
static_cast<void>(arr2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user