Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
min_max.h
Go to the documentation of this file.
1#ifndef ROUTING_KIT_MIN_MAX_H
2#define ROUTING_KIT_MIN_MAX_H
3
4#include <vector>
5#include <assert.h>
6
7namespace RoutingKit{
8
9template<class T>
10void min_to(T&x, const T&y){
11 if(y < x)
12 x = y;
13}
14
15template<class T>
16void max_to(T&x, const T&y){
17 if(y > x)
18 x = y;
19}
20
21template<class T>
22unsigned first_min_element_position_of(const std::vector<T>&v){
23 assert(!v.empty());
24 unsigned pos = 0;
25 for(unsigned i=1; i<v.size(); ++i)
26 if(v[i]< v[pos])
27 pos = i;
28 return pos;
29}
30
31template<class T>
32const T&min_element_of(const std::vector<T>&v){
34}
35
36template<class T>
37const T&min_element_of(const std::vector<T>&v, const T&empty_value){
38 if(v.empty())
39 return empty_value;
40 else
42}
43
44
45template<class T>
46unsigned first_max_element_position_of(const std::vector<T>&v){
47 assert(!v.empty());
48 unsigned pos = 0;
49 for(unsigned i=1; i<v.size(); ++i)
50 if(v[i] > v[pos])
51 pos = i;
52 return pos;
53}
54
55template<class T>
56const T&max_element_of(const std::vector<T>&v){
58}
59
60template<class T>
61const T&max_element_of(const std::vector<T>&v, const T&empty_value){
62 if(v.empty())
63 return empty_value;
64 else
66}
67
68} // RoutingKit
69
70#endif
unsigned first_max_element_position_of(const std::vector< T > &v)
Definition min_max.h:46
const T & max_element_of(const std::vector< T > &v)
Definition min_max.h:56
void min_to(T &x, const T &y)
Definition min_max.h:10
void max_to(T &x, const T &y)
Definition min_max.h:16
unsigned first_min_element_position_of(const std::vector< T > &v)
Definition min_max.h:22
const T & min_element_of(const std::vector< T > &v)
Definition min_max.h:32