本文整理汇总了C++中std::find方法的典型用法代码示例。如果您正苦于以下问题:C++ std::find方法的具体用法?C++ std::find怎么用?C++ std::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std
的用法示例。
在下文中一共展示了std::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: url
static
bool
build_url(const string &line) // line from the input file
{
try {
oodles::url::URL url(line);
cout << "Tokenised URL: " << url << endl;
cout << "Domain, Path and Page document IDs: "
<< url.domain_id() << ", "
<< url.path_id() << ", "
<< url.page_id() << endl;
cout << "Testing iterator access...";
if (find(url.begin(), url.end(), "http") != url.end())
cout << "(http scheme), ";
if (find(url.begin(), url.end(), "index.html") != url.end())
cout << "(.html index page), ";
if (count(url.begin(), url.end(), "www") > 0)
cout << "(www host).";
cout << endl;
cout << "Testing bidirectional iteratation...";
for (oodles::url::URL::iterator i = url.end() ; i != url.begin() ; )
cout << *(--i) << ",";
cout << endl << endl;
} catch (const exception &e) {
cerr << e.what();
return false;
}
return true;
}
示例2: do_type
virtual const std::string do_type() const throw ()
{
//
// A real application should use OS facilities for this. This
// is a crude hack.
//
using std::find;
using std::string;
using boost::algorithm::iequals;
using boost::next;
string media_type = "application/octet-stream";
const string::const_reverse_iterator dot_pos =
find(this->url_.rbegin(), this->url_.rend(), '.');
if (dot_pos == this->url_.rend()
|| next(dot_pos.base()) == this->url_.end()) {
return media_type;
}
const string::const_iterator hash_pos =
find(next(dot_pos.base()), this->url_.end(), '#');
const string ext(dot_pos.base(), hash_pos);
if (iequals(ext, "wrl")) {
media_type = "model/vrml";
} else if (iequals(ext, "x3dv")) {
media_type = "model/x3d+vrml";
} else if (iequals(ext, "png")) {
media_type = "image/png";
} else if (iequals(ext, "jpg") || iequals(ext, "jpeg")) {
media_type = "image/jpeg";
}
return media_type;
}
示例3: do_type
virtual const std::string do_type() const throw ()
{
//
// A real application should use OS facilities for this. This
// is a crude hack because sdl-viewer uses std::filebuf in
// order to remain simple and portable.
//
using std::find;
using std::string;
using boost::algorithm::iequals;
using boost::next;
string media_type = "application/octet-stream";
const string::const_reverse_iterator dot_pos =
find(this->url_.rbegin(), this->url_.rend(), '.');
if (dot_pos == this->url_.rend()
|| next(dot_pos.base()) == this->url_.end()) {
return media_type;
}
const string::const_iterator hash_pos =
find(next(dot_pos.base()), this->url_.end(), '#');
const string ext(dot_pos.base(), hash_pos);
if (iequals(ext, "wrl")) {
media_type = openvrml::vrml_media_type;
} else if (iequals(ext, "x3dv")) {
media_type = openvrml::x3d_vrml_media_type;
} else if (iequals(ext, "png")) {
media_type = "image/png";
} else if (iequals(ext, "jpg") || iequals(ext, "jpeg")) {
media_type = "image/jpeg";
}
return media_type;
}
示例4: unite
inline void unite(int x, int y) {
x = find(x), y = find(y);
if(x == y) { ans++; return; }
if(rank[x] < rank[y]) {
par[x] = y;
} else {
par[y] = x;
rank[x] += rank[x] == rank[y];
}
}
示例5: main
int main() {
//input
int a, b;
scanf("%d%d", &n, &m);
memset(g, false, sizeof(g));
for (int i = 0; i < m; i++) {
scanf("%d%d", &a, &b);
g[a][b] = true;
}
//floyd
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (g[i][k] && g[k][j]) g[i][j] = true;
for (int i = 1; i <= n; i++) g[i][i] = true;
//find all subsets of H
find_h(1);
//h[0]: empty set
//h[1]: Max(X)
swap(h[1], *find(h, h+num_h, max(H(true))));
/**
* pre-computing
*
* The results of the operations between items in H, consist a close
* group of itself. This means that the results are also in H.
*/
for (int i = 0; i < num_h; i++) {
for (int j = 0; j < num_h; j++) {
h_equalgreater[i][j] = find(h, h+num_h, equalgreater(h[i], h[j])) - h;
h_intersection[i][j] = find(h, h+num_h, intersection(h[i], h[j])) - h;
h_unionset[i][j] = find(h, h+num_h, unionset(h[i], h[j])) - h;
}
}
//processing
int k;
scanf("%d\n", &k);
while (k-- > 0) {
cin.getline(s, MAXL);
memset(alphabeta, -1, sizeof(alphabeta));
for (char *p = s; *p; ++p) {
if (isupper(*p))
alphabeta[*p-'A'] = 0;
else if (*p == '>') //simplify the input, "=>" --> ">"
*(p-1) = ' ';
}
printf(solve(0)?"valid\n":"invalid\n");
}
return 0;
}
示例6: connect_face
void Mesh::connect_face(int u, int v) {
if (u == v)
return;
if (find(adj_face[u].begin(), adj_face[u].end(), v) != adj_face[u].end())
return;
adj_face[u].push_back(v);
}
示例7: removeEntity
void World::removeEntity(const shared_ptr<Entity> &entity) {
auto it = find(m->entities.begin(), m->entities.end(), entity);
if (it == m->entities.end()) {
throw std::runtime_error("Entity is not there to remove!");
}
m->entities.erase(it);
}
示例8: find
/*
* Fetches a tile from a specific set specified by set_number
* Returns the fetched tile.
*/
shared_ptr<Tile> Model::fetch_tile_from_set( int set_number, string tile_name ){
Set* set = get_set_from_table( set_number );
shared_ptr<Tile> tile = set->get_and_erase_tile( tile_name );
if (tile->is_joker()) {
tile->reset_joker();
}
cout << "Fetched " << tile->get_name() << " from set " << set_number << endl;
// If there is only one tile left in set, fetch the remaining tile
if (set->size() == 1) {
string last_tile_name = set->get_tiles().front()->get_name();
cout << "Automatically fecthed last tile " << last_tile_name << " from set " << set_number << " to hand" << endl;
shared_ptr<Tile> last_tile = set->get_and_erase_tile( last_tile_name );
if (last_tile->is_joker()) {
last_tile->reset_joker();
}
Model::get_instance().add_fetched_tile_to_hand( last_tile );
// Remove set since all tiles have been fetched
auto it = find(table.begin(), table.end(), set);
table.erase(it);
}
return tile;
}
示例9: contains
bool contains(const table& tbl, int val)
{ // return true if tbl contains val
int hash_val = hash(val) % tbl.size();
bucket::const_iterator first = tbl[hash_val].begin();
bucket::const_iterator last = tbl[hash_val].end();
return find(first, last, val) != last;
}
示例10: goal
bool goal(const TCandidate &candidate,
const string::const_iterator &query_end,
float &min_suggestion_prob,
vector<string> &suggestions)
{
if (candidate.node->sub_trees.size() > 0) // leaf has no subtrees
return false;
if (candidate.query != query_end) // query must be already matched at trie leaf
return true;
// remove string delimiter in trie
string suggestion(candidate.suggestion.substr(0, candidate.suggestion.size() - 1));
// no duplicates in results allowed
if (find(suggestions.begin(), suggestions.end(), suggestion) == suggestions.end())
{
// set criterion that P(solution) must be greater that P(best solution) / 100
if (suggestions.empty())
min_suggestion_prob = candidate.probability / (float)100.;
suggestions.push_back(suggestion);
}
return true;
}
示例11: Rename
void HelpConfigDialog::Rename(wxCommandEvent &event)
{
wxListBox *lst = XRCCTRL(*this, "lstHelp", wxListBox);
wxString orig = lst->GetString(lst->GetSelection());
wxString text = wxGetTextFromUser(_("Rename this help file title:"), _("Rename title"), orig);
if (!text.IsEmpty())
{
HelpCommon::HelpFilesVector::iterator logEnd = m_Vector.end() - HelpCommon::getNumReadFromIni();
HelpCommon::HelpFilesVector::iterator it = find(m_Vector.begin(), logEnd, text);
if (it != logEnd)
{
cbMessageBox(_("This title is already in use."), _("Warning"), wxICON_WARNING);
return;
}
if (text.Find(_T('/')) != -1 || text.Find(_T('\\')) != -1)
{
cbMessageBox(_("Slashes and backslashes cannot be used to name a help file."), _("Warning"), wxICON_WARNING);
return;
}
m_Vector[lst->GetSelection()].first = text;
lst->SetString(lst->GetSelection(), text);
}
}
示例12: initializeTFile
TFile* histfiles::initializeTFile(const char *processor_name, bool debug) {
stringstream _name;
_name << processor_name;
if(_name.str()=="") _name.str("cafe");
Config config(_name.str().c_str());
string _output = config.get("Output", "result.root");
if(debug) cout << "histfiles::initializeTFile:"
<< " PROCESSOR_NAME=" << _name.str()
<< " OUTPUT_FILE=" << _output
<< endl;
if (_output=="") return NULL;
// keep track of rootuples that have been already created during this session
TFile *f = NULL;
if (find(_histfiles_created.begin(),
_histfiles_created.end(),
_output) == _histfiles_created.end()) {
if(debug) cout << "histfiles::initializeTFile: Output file has not been opened yet" << endl;
f = new TFile(_output.c_str(),"RECREATE");
if (f!=NULL) {
_histfiles_created.push_back(_output);
}
} else {
if(debug) cout << "histfiles::initializeTFile: Output file has been already created" << endl;
f = new TFile(_output.c_str(),"UPDATE");
}
return f;
}
示例13: release
bool
release(ObjectType* theInstance)
{
#if !defined(XALAN_NO_STD_NAMESPACE)
using std::find;
#endif
typedef typename VectorType::iterator IteratorType;
const IteratorType i =
find(
m_busyList.begin(),
m_busyList.end(),
theInstance);
if (i == m_busyList.end())
{
return false;
}
else
{
m_resetFunctor(theInstance);
m_availableList.push_back(theInstance);
m_busyList.erase(i);
return true;
}
}
示例14: operator
auto operator()(const T & t, const C<T> & c) const {
using std::find;
auto found = find(c.begin(), c.end(), t);
return found != c.end();
}
示例15: UpdateIndicies
void UpdateIndicies(Device const& device)
{
vector<DWORD>& channelIndicies = m_channelsIndicies[device.DeviceID()];
vector<string>const& channelStrings = m_channels[device.DeviceID()];
channelIndicies.clear();
// Create a list of strings from the device
vector<string> sourceNames = device.GetChannelNames();
vectorStringIter sourceBegin = sourceNames.begin();
vectorStringIter sourceEnd = sourceNames.end();
// do a search for each name
for(vectorStringIter iter = channelStrings.begin();
iter < channelStrings.end(); ++iter)
{
vectorStringIter item = find(sourceBegin, sourceEnd, *iter);
if (item == sourceEnd)
{
UCSBUtility::LogError("Data Aggregator config failure: "
"%s field does not exist in device %s", iter->c_str(),
device.DisplayName().c_str());
}
else
{
channelIndicies.push_back(item - sourceBegin);
}
}
}