mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
Use wpi::span instead of wpi::ArrayRef across all libraries (#3414)
- Remove ArrayRef.h - Add SpanExtras.h for a couple of convenience functions
This commit is contained in:
27
wpiutil/src/main/native/include/wpi/SpanExtras.h
Normal file
27
wpiutil/src/main/native/include/wpi/SpanExtras.h
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "wpi/span.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
/// Drop the first \p N elements of the array.
|
||||
template <typename T>
|
||||
constexpr span<T> drop_front(span<T> in, typename span<T>::size_type n = 1) {
|
||||
assert(in.size() >= n && "Dropping more elements than exist");
|
||||
return in.subspan(n, in.size() - n);
|
||||
}
|
||||
|
||||
/// Drop the last \p N elements of the array.
|
||||
template <typename T>
|
||||
constexpr span<T> drop_back(span<T> in, typename span<T>::size_type n = 1) {
|
||||
assert(in.size() >= n && "Dropping more elements than exist");
|
||||
return in.subspan(0, in.size() - n);
|
||||
}
|
||||
|
||||
} // namespace wpi
|
||||
Reference in New Issue
Block a user