当前位置: 首页>>代码示例>>C++>>正文


C++ std::find_if方法代码示例

本文整理汇总了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;
}
开发者ID:1e0nshe11,项目名称:Cpp-Primer,代码行数:35,代码来源:ex17_33.cpp

示例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;
  
}
开发者ID:JesseLiu0,项目名称:coursework,代码行数:25,代码来源:split.cpp

示例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;
    }
}
开发者ID:edrummon,项目名称:NetBeans,代码行数:13,代码来源:main.cpp

示例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;
    }
}
开发者ID:570468837,项目名称:Daily-pracitce,代码行数:15,代码来源:split_algo.cpp

示例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());
}
开发者ID:adelbertc,项目名称:misc,代码行数:16,代码来源:cdf.cpp

示例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]);
		}
	}
}
开发者ID:kevinGC,项目名称:waegyopp,代码行数:25,代码来源:Terr.cpp

示例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);
}
开发者ID:nsadovskiy,项目名称:communicator,代码行数:25,代码来源:settings.cpp

示例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;
    }
  }
}
开发者ID:Telhar,项目名称:unisolver,代码行数:29,代码来源:lvl_tree.cpp

示例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( ... )
开发者ID:mavak,项目名称:trucov,代码行数:36,代码来源:selector.cpp

示例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);
    });
}
开发者ID:karllen,项目名称:kuplayer,代码行数:25,代码来源:play_list_widget.cpp

示例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;
}
开发者ID:Cuculidae,项目名称:Learn,代码行数:26,代码来源:lambda.cpp

示例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{};
}
开发者ID:sansajn,项目名称:aexplor,代码行数:8,代码来源:directory_model.cpp

示例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);
        });
}
开发者ID:rachelwang,项目名称:dreal,代码行数:17,代码来源:ode_solver.cpp

示例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;
    }
}
开发者ID:570468837,项目名称:Daily-pracitce,代码行数:18,代码来源:14.cpp

示例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 ;
}
开发者ID:Deseaus,项目名称:GF,代码行数:18,代码来源:gfex.cpp


注:本文中的std::find_if方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。