本文整理匯總了C++中std::find_if方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::find_if方法的具體用法?C++ std::find_if怎麽用?C++ std::find_if使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類std
的用法示例。
在下文中一共展示了std::find_if方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: main
int main() {
typedef pair<string, string> ps;
ifstream i("d.txt");
vector<ps> dict;
string str1, str2;
// read wirds from dictionary
while (i >> str1 >> str2) {
dict.emplace_back(str1, str2);
}
i.close();
// sort words in vector
sort(dict.begin(), dict.end(), [](const ps &_ps1, const ps &_ps2){ return _ps1.first < _ps2.first; });
i.open("i.txt");
default_random_engine e(time(0));
// read words from text
while (i >> str1) {
// find word in dictionary
vector<ps>::const_iterator it = find_if(dict.cbegin(), dict.cend(),
[&str1](const ps &_ps){ return _ps.first == str1; });
// if word doesn't exist in dictionary
if (it == dict.cend()) {
// write it itself
cout << str1 << ' ';
}
else {
// get random meaning of word
uniform_int_distribution<unsigned> u (0, find_if(dict.cbegin(), dict.cend(),
[&str1](const ps &_ps){ return _ps.first > str1; }) - it - 1);
// write random meaning
cout << (it + u(e))->second << ' ';
}
}
return 0;
}
示例2: split
vector<string> split(const string& str)
{
typedef string::const_iterator iter;
vector<string> ret;
iter i = str.begin();
while (i != str.end())
{
//ignore leading blanks
i = find_if(i, str.end(), not_space);
//find end of next word
iter j = find_if(i, str.end(), space);
//copy the characters in [i,j)
if (i != str.end())
ret.push_back(string(i,j));
i = j;
}
return ret;
}
示例3: split
void split(const string& str, StringList& strList) {
typedef string::const_iterator iter;
iter i = str.begin();
while (i != str.end()) {
i = find_if(i, str.end(), not_space);
iter j = find_if(i, str.end(), space);
if (i != j)
strList.addString(string(i, j));
i = j;
}
}
示例4: split
void split(const string& s, Out os){
typedef string::const_iterator siter;
siter b = s.begin();
siter e = s.end();
while(b != e){
siter word = find_if(b, e, not_space);
siter word_end = find_if(word, e, space);
if (word != e){
*os++ = string(word, word_end);
}
b = word_end;
}
}
示例5: last_in_line
double last_in_line(const string& str)
{
typedef string::const_iterator iter;
vector<string> ret;
iter i = str.begin();
while (i != str.end()) {
i = find_if(i, str.end(), not_space);
iter j = find_if(i, str.end(), space);
if (i != str.end())
ret.push_back(string(i, j));
i = j;
}
return atof(ret[ret.size() - 1].c_str());
}
示例6: get_val
Terr::Terr(const Json::Value& loc,
const Json::Value locs,
map<string, shared_ptr<Terr>>& terrs)
: short_name{get_val("short_name", loc).asString()}
, display_name{get_val("display_name", loc).asString()}
, has_center{get_val("has_center", loc).asBool()}
, adjacent{}
, piece{}
{
terrs[short_name] = shared_ptr<Terr>(this); // sketchy...
assert(terrs.find(short_name) != terrs.end());
for(const auto& adj_val : get_val("adjacent", loc)) {
string adj_name = adj_val.asString();
if(terrs.find(adj_name) == terrs.end()) {
const auto it = find_if(locs.begin(), locs.end(),
[&adj_name](const Json::Value& t) {
return get_val("short_name", t) == adj_name;
});
assert(it != locs.end());
set_terrs(*it, locs, terrs);
assert(terrs.find(adj_name) != terrs.end()); // TODO NDEBUG
adjacent.push_back(terrs[adj_name]);
}
}
}
示例7: get_settings
void get_settings(int argc, const char * argv[], std::vector<communicator::options_t> & options, bool & daemon_mode) {
using std::vector;
using std::find_if;
// Check mode daemon or console
vector<const char *> kw = {
"daemon", "-daemon", "--daemon", "/daemon", "\\daemon",
"service", "-service", "--service", "/service", "\\service"
};
if (argc > 1) {
const string param = argv[1];
auto pos = find_if(kw.begin(), kw.end(), [param](const char * val) { return val == param; });
if (kw.end() == pos) {
ostringstream err;
err << "Unknown option: '" << param << "'. Valid values are 'daemon' or 'service'\n";
throw runtime_error(err.str());
}
daemon_mode = true;
}
// Read options from config file
read_settings_from_file("communicator.conf", options);
}
示例8: _add_flag_fill_width
void LvlTree::_add_flag_fill_width (Params p,
list<AMRGrid>& new_grids,
vector<AMRGrid>& old_grids,
int n,
real h) {
auto rdelta = p.amr.flag_fill_width * h;
auto delta = p.amr.flag_fill_width;
auto l = 0 + delta;
auto r = n - 1 - delta;
for (auto& el : new_grids) {
if (!old_grids.empty ()
&& find_if (
begin (old_grids),
end (old_grids),
[el](AMRGrid a) { return a == el; }
) != end (old_grids))
continue;
if (el.x1 >= l) {
el.rx1 -= rdelta;
el.x1 -= delta;
}
if (el.x2 <= r) {
el.rx2 += rdelta;
el.x2 += delta;
}
}
}
示例9: check_in_selection
//////////////////////////////////////////////////////////////////////////////
/// @brief
/// Returns if the string can be matched to an expression
///
/// @param input The string to be matched to a regex
/// @param expression The regex expression
///
/// @return bool
//////////////////////////////////////////////////////////////////////////////
bool Selector::check_in_selection( const std::string & input )
{
// The function pointer type of the overloaded match_regex we will use
// for matching.
typedef bool (*Regex_match_ptr)( const string &, const regex &,
match_flag_type);
// Set match flag to full match or partial match, whatever was selected.
match_flag_type match_type = match_default;
if ( !is_and_match )
{
// Check regex_match(input, ith expression, match_type) matches any
// of the expressions in selection list. We must cast regex_match to the
// overloaded function pointer type we are using.
return ( find_if( regex_selections.begin(), regex_selections.end(),
bind( static_cast<Regex_match_ptr>( regex_match ), input, _1,
match_type ) ) != regex_selections.end() );
}
else
{
return ( count_if( regex_selections.begin(), regex_selections.end(),
bind( static_cast<Regex_match_ptr>( regex_match ), input, _1,
match_type ) ) == regex_selections.size() );
}
} // End of Selector::check_in_selection( ... )
示例10: sort
void PlayListWidget::sort(const QStringList &list)
{
static QString first;
static QString second;
static QStringList tmp;
static auto comp = [](QString::value_type it) {return it.isDigit();};
for_each(list.begin(), list.end(), [&](const QStringList::value_type & item) {
second.clear();
tmp = item.split("$$");
first = tmp[0];
auto digit_begin = find_if(first.begin(), first.end(), comp);
auto digit_end = find_if_not(digit_begin, first.end(), comp);
std::copy(digit_begin, digit_end, std::back_inserter(second));
play_list.append(list_map {std::make_tuple<QString, QString, QString>(
QString("%1").arg(second.toInt(), 10, 10, QChar('0')),
std::move(first),
std::move(tmp[1]))
});
});
std::sort(play_list.begin(), play_list.end(),
[](list_map::const_iterator::value_type lvalue,
list_map::const_iterator::value_type rvalue) {
return std::get<0>(lvalue) < std::get<0>(rvalue);
});
}
示例11: biggies
void biggies(vector<string> &words, vector<string>::size_type sz)
{
elimDups(words); // put words in alphabetical order and remove duplicates
// resort by length, maintaining alphabetical order among words of the same
// length
stable_sort(words.begin(), words.end(),
[](const string &s1, const string &s2)
{
return s1.size() < s2.size();
});
// get an iterator to the first element whose size() is >= sz
auto wc = find_if(words.begin(), words.end(),
[sz] (const string &s) {
return s.size() >= sz;
});
// compute the number of elements with size >= sz
auto count = words.end() - wc;
cout << count << " " << make_plural(count, "word", "s")
<< " of length " << sz << " or longer" << endl;
// print words of the given size or longer, each one followed by space
for_each(wc, words.end(),
[] (const string &s) {
cout << s << " ";
});
cout << endl;
}
示例12: find
QModelIndex directory_model::find(std::string const & file_name) const
{
list<file_info>::const_iterator it = find_if(_files.begin(), _files.end(), find_by_name{file_name});
if (it != _files.end())
return index(distance(_files.begin(), it));
else
return QModelIndex{};
}
示例13: prune_trajectory
void ode_solver::prune_trajectory(interval& time, IVector& e) {
// Remove datapoints after time interval.
auto ite = find_if (m_trajectory.begin(),
m_trajectory.end(),
[&time](pair<interval, IVector>& item) {
return item.first.leftBound() > time.rightBound();
});
m_trajectory.erase(ite, m_trajectory.end());
// Update the datapoints in the time interval
ite = find_if (m_trajectory.begin(), m_trajectory.end(), [&time](pair<interval, IVector>& item) {
return item.first.leftBound()>= time.leftBound();
});
for_each(ite, m_trajectory.end(), [&e](pair<interval, IVector>& item) {
intersection(item.second, e, item.second);
});
}
示例14: split
void split(const string& s, Out o){
typedef string::const_iterator sit;
sit b = s.begin();
sit e = s.end();
while (b != e) {
sit word = find_if(b, e, nspace);
sit word_end = find_if(word, e, space);
sit nword = find_if(word_end, e, nspace);
if (word_end != e){
string temp = string(word, nword);
if (find_if(temp.begin(), temp.end(), not_legal) == temp.end()){
*o++ = temp;
}
}
b = word_end;
}
}
示例15: words
vector<string> words(const string& s)
{
typedef string::const_iterator iter ;
vector<string> ws ;
iter i = s.begin() ;
while (i != s.end()) {
// ignore space
i = find_if(i, s.end(), not_space) ;
// collect characters until space
iter j = find_if(i, s.end(), space) ;
// add the string to the vector
if (i != s.end())
ws.push_back(string(i,j)) ;
i = j ;
}
return ws ;
}