WPILibC++ 2023.4.3
Algorithm.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 <algorithm>
8#include <vector>
9
10namespace wpi {
11
12// Binary insertion into vector; std::log(n) efficiency.
13template <typename T>
14typename std::vector<T>::iterator insert_sorted(std::vector<T>& vec,
15 T const& item) {
16 return vec.insert(std::upper_bound(vec.begin(), vec.end(), item), item);
17}
18} // namespace wpi
/file This file defines the SmallVector class.
Definition: AprilTagFieldLayout.h:18
std::vector< T >::iterator insert_sorted(std::vector< T > &vec, T const &item)
Definition: Algorithm.h:14