當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。