本文整理匯總了C++中std::for_each方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::for_each方法的具體用法?C++ std::for_each怎麽用?C++ std::for_each使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類std
的用法示例。
在下文中一共展示了std::for_each方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: stop
void Tunnel::stop()
{
auto d = Tunnel::_instance->d_func();
auto stopDispatcherFunc =
[](TunnelPrivate::DispatcherMap::value_type& pair)
{
winfo("Stopping the " + pair.second->name() + " dispatcher...");
assert(pair.second);
pair.second->stop();
winfo("Stopped the " + pair.second->name() + " dispatcher.");
};
auto stopReceiverFunc =
[](TunnelPrivate::ReceiverMap::value_type& pair)
{
winfo("Stopping the " + pair.second->name() + " receiver...");
assert(pair.second);
pair.second->stop();
winfo("Stopped the " + pair.second->name() + " receiver.");
};
wdebug("Stopping the Tunnel...");
for_each(begin(d->receivers), end(d->receivers), stopReceiverFunc);
for_each(begin(d->dispatchers), end(d->dispatchers), stopDispatcherFunc);
instance()->emitEvent(make_shared<Events::Event>(W_EVENT_TUNNEL_STOP));
wdebug("Stopped the Tunnel.");
}
示例2: start
void Tunnel::start()
{
W_SPRV(Tunnel);
auto startDispatcherFunc =
[](std::pair<const string, Tunnel::Dispatcher::Ptr> pair)
{
winfo("Starting the " + pair.second->name() + " dispatcher...");
assert(pair.second);
pair.second->start();
winfo("Started the " + pair.second->name() + " dispatcher.");
};
auto startReceiverFunc =
[](std::pair<const string, Tunnel::Receiver::Ptr> pair)
{
winfo("Starting the " + pair.second->name() + " receiver...");
assert(pair.second);
pair.second->start();
winfo("Started the " + pair.second->name() + " receiver.");
};
wdebug("Starting the Tunnel...");
for_each(begin(d->receivers), end(d->receivers), startReceiverFunc);
for_each(begin(d->dispatchers), end(d->dispatchers), startDispatcherFunc);
auto eventPtr = make_shared<Events::Event>(W_EVENT_TUNNEL_START);
assert(instance()->emitter());
instance()->emitEvent(eventPtr);
wdebug("Started the Tunnel.");
}
示例3: main
int main(int argc, char* argv[])
{
///
/// Command line arguments processing
///
if (argc < 5) {
usage();
return 0;
}
vector<string> prev_trans_directory;
prev_trans_directory.push_back(argv[1]);
string dir_of_project_folder = argv[2];
string libname = argv[3];
vector<string> dlls;
for (int i = 4; i < argc; i++) {
dlls.push_back(argv[i]);
}
///
/// If there are any other directories that contain libraries we've previously translated,
/// pick up all the previously translated things from there
///
LibraryConverterDriver driver;
for_each(prev_trans_directory.begin(), prev_trans_directory.end(), [&driver] (const string &s) { driver.add_converted_info(s);});
///
/// Ok, now specify the list of libraries we want translated
///
for_each(dlls.begin(), dlls.end(), [&driver] (const string &s) { driver.translate_classes_in_library(s); });
///
/// The specifics (output location, etc.)
///
driver.set_output_solution_directory(dir_of_project_folder);
driver.write_solution(false);
driver.use_class_header_locations(true);
driver.write_all_in_single_library(libname);
driver.print_error_report(false);
driver.set_template_files_location (prev_trans_directory[0] + "\\bin");
///
/// Now, do the translation and write out the final project solutoin
///
try {
driver.translate();
} catch (exception &e)
{
cout << "ERROR translating: " << e.what() << endl;
return 100;
}
}
示例4: main
int
main()
{
using boost::phoenix::arg_names::arg1;
using boost::phoenix::construct;
using boost::phoenix::delete_;
using boost::phoenix::new_;
using std::for_each;
using std::vector;
{
vector<X*> v(10);
for_each(v.begin(), v.end(), arg1 = new_<X>());
for_each(v.begin(), v.end(), delete_(arg1));
for_each(v.begin(), v.end(), arg1 = new_<X>(1, 2, 3));
for_each(v.begin(), v.end(), delete_(arg1));
}
{
using boost::shared_ptr;
vector<shared_ptr<X> > v(10);
for_each(v.begin(), v.end(),
arg1 = boost::phoenix::construct<shared_ptr<X> >(new_<X>())
);
}
BOOST_TEST(n == 0);
return boost::report_errors();
}
示例5:
// adds one CDataFile to another CDataFile
CDataFile& CDataFile::operator+=(const CDataFile& df)
{
for_each
(
df.m_vstrVariableNames.begin(),
df.m_vstrVariableNames.end(),
AddTo(m_vstrVariableNames)
);
for_each
(
df.m_vstrSourceFilenames.begin(),
df.m_vstrSourceFilenames.end(),
AddTo(m_vstrSourceFilenames)
);
for_each
(
df.m_v2dData.begin(),
df.m_v2dData.end(),
AddTo(m_v2dData)
);
for_each
(
df.m_v2dStrData.begin(),
df.m_v2dStrData.end(),
AddTo(m_v2dStrData)
);
return *this;
}
示例6: describe
// tell all objects to describe themselves to the console
void Model::describe() const {
for_each(m_sim_objs.begin(), m_sim_objs.end(),
[](const Sim_objs_t::value_type& p){ p.second->describe(); });
for_each(m_groups.begin(), m_groups.end(),
[](const shared_ptr<Group>& p){ p->describe(); });
}
示例7: demo_savem
void demo_savem()
{
ofstream out_file("output.txt"); // open a file for output
list<Thing *> thing_ptrs;
// tell each thing to save its data to the out_file stream
for_each(thing_ptrs.begin(), thing_ptrs.end(), Savem(out_file));
// using a lambda
for_each(thing_ptrs.begin(), thing_ptrs.end(),
[&out_file](Thing * ptr){ptr->save(out_file);} );
}
示例8: msg
bool KEY6Parser::parseSlideList(const unsigned id)
{
const ObjectMessage msg(*this, id, KEY6ObjectType::SlideList);
if (!msg)
return false;
const deque<unsigned> &slideListRefs = readRefs(get(msg), 1);
for_each(slideListRefs.begin(), slideListRefs.end(), bind(&KEY6Parser::parseSlideList, this, _1));
const deque<unsigned> &slideRefs = readRefs(get(msg), 2);
for_each(slideRefs.begin(), slideRefs.end(), bind(&KEY6Parser::parseSlide, this, _1, false));
return true;
}
示例9: initTiles
void LocationMap::initTiles() {
bool hi = false;
for_each(tiles.begin(), tiles.end(), [&hi](vector<TileShared>& col) {
for_each(col.begin(), col.end(), [&hi](TileShared& tile) {
// Closures. Neat! hi is fed in as a reference.
tile.reset(new Tile());
hi = !hi;
tile->setDerp(hi);
} );
} );
}
示例10: OnInitDialog
END_EASYSIZE_MAP
/////////////////////////////////////////////////////////////////////////////
BOOL CMainDialog::OnInitDialog()
{
CDialog::OnInitDialog();
//////////////////////////////////////////////////////////////////////////
CMenu *pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL) {
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty()) {
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
//////////////////////////////////////////////////////////////////////////
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
//////////////////////////////////////////////////////////////////////////
GetWindowRect(&m_rtMinSize);
INIT_EASYSIZE;
InitControl();
GetImageSize(m_dwWidth, m_dwHeight);
m_dwFrameStart = 0;
m_dwFrameFinish= 0;
for_each(nIDGroupPlay, nIDGroupPlay + ItemCount(nIDGroupPlay), bind1st(EnableWnd<FALSE>(), this));
//////////////////////////////////////////////////////////////////////////
if (PathFileExists(m_szSrcFilePath)) {
SetTimer(0, 1000 / GetDlgItemInt(IDC_EDT_FPS, NULL, FALSE), NULL);
SetDlgItemText(IDC_EDT_SRC_PATH, m_szSrcFilePath);
for_each(nIDGroupPlay, nIDGroupPlay + ItemCount(nIDGroupPlay), bind1st(EnableWnd<TRUE>(), this));
m_fileSrc.Create(m_szSrcFilePath, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING);
m_fileSrc.GetSize(m_dwFileLength);
Update(TRUE);
}
Update(FALSE);
return TRUE;
}
示例11: biggies
void biggies(vector<string> & words, vector<string>::size_type sz) {
elimDups(words);
auto iter = stable_partition(words.begin( ), words.end( ), [sz](const string & s) {return sz > s.size( ); });
for_each(iter, words.end( ), [ ](const string & s) {cout << s << ' '; });
cout << endl;
}
示例12: 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;
}
示例13: 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);
});
}
示例14: update
void Model::update()
{
++time;
for_each(object_container.begin(), object_container.end(),
bind(&Sim_object::update,
bind(& map<string, shared_ptr<Sim_object> >::value_type::second, _1)));
}
示例15: get_count_over_criterion
// returns the number of ints greater than criterion
int get_count_over_criterion()
{
count = 0;
for_each(ints.begin(), ints.end(),
[this](int i) {if (i > criterion) count++;} );
return count;
}