WPILibC++ 2023.4.3
SpanExtras.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 <cassert>
8#include <span>
9
10namespace wpi {
11
12/// Drop the first \p N elements of the array.
13template <typename T>
14constexpr std::span<T> drop_front(std::span<T> in,
15 typename std::span<T>::size_type n = 1) {
16 assert(in.size() >= n && "Dropping more elements than exist");
17 return in.subspan(n, in.size() - n);
18}
19
20/// Drop the last \p N elements of the array.
21template <typename T>
22constexpr std::span<T> drop_back(std::span<T> in,
23 typename std::span<T>::size_type n = 1) {
24 assert(in.size() >= n && "Dropping more elements than exist");
25 return in.subspan(0, in.size() - n);
26}
27
28} // namespace wpi
/file This file defines the SmallVector class.
Definition: AprilTagFieldLayout.h:18
constexpr std::span< T > drop_back(std::span< T > in, typename std::span< T >::size_type n=1)
Drop the last N elements of the array.
Definition: SpanExtras.h:22
constexpr std::span< T > drop_front(std::span< T > in, typename std::span< T >::size_type n=1)
Drop the first N elements of the array.
Definition: SpanExtras.h:14