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


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

本文整理汇总了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.");
}
开发者ID:jalcine,项目名称:wintermute,代码行数:29,代码来源:tunnel.cpp

示例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.");
}
开发者ID:jalcine,项目名称:wintermute,代码行数:30,代码来源:tunnel.cpp

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

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

示例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;
}
开发者ID:ferreiramx,项目名称:libpr,代码行数:33,代码来源:DataFile.cpp

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

示例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);} );
}
开发者ID:zincxenon,项目名称:381,代码行数:12,代码来源:lamba_demo.cpp

示例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;
}
开发者ID:fosnola,项目名称:libetonyek,代码行数:12,代码来源:KEY6Parser.cpp

示例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);
        } );
    } );

}
开发者ID:wittekm,项目名称:SDL2-C--11-Test,代码行数:13,代码来源:LocationMap.cpp

示例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;
}
开发者ID:LiuYinChina,项目名称:YUVViewer,代码行数:51,代码来源:MainDialog.cpp

示例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;

}
开发者ID:webary,项目名称:CppPrimer,代码行数:7,代码来源:10_19.cpp

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

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

示例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)));
}
开发者ID:shilinf,项目名称:381_5,代码行数:7,代码来源:Model.cpp

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


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