BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
Utility.h File Reference
#include <vector>
#include <algorithm>
#include <utility>

Go to the source code of this file.

Macros

#define _H_FACILITIES_UTILITY
 

Functions

template<class FwdIt , class UniPred , class BinPred >
std::pair< FwdIt, FwdIt > adjacent_find_if (const FwdIt &first, const FwdIt &last, UniPred if_pred, BinPred adj_pred)
 
template<class FwdIt , class UniPred , class BinPred >
std::vector< FwdIt > adjacent_find_multiple (const FwdIt &first, const FwdIt &last, UniPred if_pred, BinPred adj_pred, unsigned N=2)
 

Macro Definition Documentation

◆ _H_FACILITIES_UTILITY

#define _H_FACILITIES_UTILITY

Definition at line 5 of file Utility.h.

Function Documentation

◆ adjacent_find_if()

template<class FwdIt , class UniPred , class BinPred >
std::pair< FwdIt, FwdIt > adjacent_find_if ( const FwdIt &  first,
const FwdIt &  last,
UniPred  if_pred,
BinPred  adj_pred 
)
inline

Definition at line 20 of file Utility.h.

21{
22 FwdIt i = std::find_if( first, last, if_pred );
23 FwdIt j = i;
24 if (i != last) i = std::find_if( ++i, last, if_pred );
25 while (i != last) {
26 if (adj_pred ( (*j), (*i) )) return std::make_pair(j,i);
27 j = i++;
28 while (!(if_pred(*i)) && (i != last)) ++i;
29 }
30 return std::make_pair(last, last);
31}

Referenced by adjacent_find_multiple().

◆ adjacent_find_multiple()

template<class FwdIt , class UniPred , class BinPred >
std::vector< FwdIt > adjacent_find_multiple ( const FwdIt &  first,
const FwdIt &  last,
UniPred  if_pred,
BinPred  adj_pred,
unsigned  N = 2 
)
inline

Definition at line 34 of file Utility.h.

44{
45 std::vector<FwdIt> itvec;
46 std::pair<FwdIt, FwdIt> adjpr1 = adjacent_find_if( first, last, if_pred, adj_pred );
47 if (adjpr1.second == last) return itvec;
48
49 itvec.push_back( adjpr1.first);
50 itvec.push_back( adjpr1.second );
51 std::pair<FwdIt, FwdIt> adjpr2;
52
53 while ((itvec.size() < N) && (adjpr1.second != last)) {
54 adjpr2 = adjacent_find_if( adjpr1.second, last, if_pred, adj_pred );
55 if (adjpr2.second == last) return std::vector<FwdIt>();
56 if (adj_pred((*adjpr1.second), (*adjpr2.second))) itvec.push_back(adjpr2.second);
57 else {
58 itvec.clear();
59 itvec.push_back(adjpr2.first);
60 itvec.push_back(adjpr2.second);
61 }
62 adjpr1.second = adjpr2.second;
63 }
64 return itvec;
65}
std::pair< FwdIt, FwdIt > adjacent_find_if(const FwdIt &first, const FwdIt &last, UniPred if_pred, BinPred adj_pred)
Definition: Utility.h:20