ATLAS Offline Software
Loading...
Searching...
No Matches
find_bin.h
Go to the documentation of this file.
1
12
13
14#ifndef IDTPM2_BINS_FIND_BIN
15#define IDTPM2_BINS_FIND_BIN
16
17#include <vector>
18#include <stdexcept>
19
20
21namespace IDTPM2::bins {
22
23template<typename T,typename U=T>
24size_t find_bin( const std::vector<T>& v, const U& x ) {
25 if ( v.size()<2) throw std::runtime_error("cannot define a bin range with fewer than two limits");
26 if ( x>=v.back() ) return v.size()-2;
27 if ( x<v.front() ) return 0;
28 typename std::vector<T>::const_iterator itr = std::lower_bound( v.begin(), v.end(), x );
29 return (itr-v.begin())-1;
30}
31
32}
33
34#endif // IDTPM2_BINS_FIND_BIN
35
#define x
size_t find_bin(const std::vector< T > &v, const U &x)
Definition find_bin.h:24