#include <vector>
#include <algorithm>
#include <utility>
Go to the source code of this file.
Defines | |
#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) |
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.
References genRecEmupikp::i, and ganga-rec::j.
Referenced by adjacent_find_multiple().
00021 { 00022 FwdIt i = std::find_if( first, last, if_pred ); 00023 FwdIt j = i; 00024 if (i != last) i = std::find_if( ++i, last, if_pred ); 00025 while (i != last) { 00026 if (adj_pred ( (*j), (*i) )) return std::make_pair(j,i); 00027 j = i++; 00028 while (!(if_pred(*i)) && (i != last)) ++i; 00029 } 00030 return std::make_pair(last, last); 00031 }
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.
References adjacent_find_if(), and TrigConf::N.
00042 : one for the individual element adjacency, and another for group 00043 // adjacency (that is there are two levels of adjacency here.) 00044 { 00045 std::vector<FwdIt> itvec; 00046 std::pair<FwdIt, FwdIt> adjpr1 = adjacent_find_if( first, last, if_pred, adj_pred ); 00047 if (adjpr1.second == last) return itvec; 00048 00049 itvec.push_back( adjpr1.first); 00050 itvec.push_back( adjpr1.second ); 00051 std::pair<FwdIt, FwdIt> adjpr2; 00052 00053 while ((itvec.size() < N) && (adjpr1.second != last)) { 00054 adjpr2 = adjacent_find_if( adjpr1.second, last, if_pred, adj_pred ); 00055 if (adjpr2.second == last) return std::vector<FwdIt>(); 00056 if (adj_pred((*adjpr1.second), (*adjpr2.second))) itvec.push_back(adjpr2.second); 00057 else { 00058 itvec.clear(); 00059 itvec.push_back(adjpr2.first); 00060 itvec.push_back(adjpr2.second); 00061 } 00062 adjpr1.second = adjpr2.second; 00063 } 00064 return itvec; 00065 }