WPILibC++  2020.3.2
Algorithm.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <vector>
11 
12 namespace wpi {
13 
14 // Binary insortion into vector; std::log(n) efficiency.
15 template <typename T>
16 typename std::vector<T>::iterator insert_sorted(std::vector<T>& vec,
17  T const& item) {
18  return vec.insert(std::upper_bound(vec.begin(), vec.end(), item), item);
19 }
20 } // namespace wpi
wpi
WPILib C++ utilities (wpiutil) namespace.
Definition: EventLoopRunner.h:17