当前位置:网站首页>for_each用法示例
for_each用法示例
2022-07-29 03:25:00 【3D视觉工坊】
前言
由于偶然间发现for_each能使得避免使用for循环,大大简化了代码。这里简单记录下for_each的一个简单示例demo,方便温习。
示例demo
#include <iostream>
#include "vector"
#include "algorithm"
void myfunc1(int i)
{
std::cout << i << " ";
}
int main() {
std::vector<int> arr{
3, 4, 2, 6, 5, 1 };
std::cout << "based on for_each, print the vector\n";
for_each(arr.begin(), arr.end(), myfunc1);
std::cout << "\n";
std::cout << "based on lambda, print the vector\n";
for_each(arr.begin(), arr.end(), [](const auto &i){
std::cout << i << " ";});
return 0;
}

边栏推荐
- Incremental real-time disaster recovery notes
- LeetCode 1331 数组序号转换[Map] HERODING的LeetCode之路
- Complexity analysis learning
- Microcomputer principle operation
- Minesweeping simple version
- Multiline text omission
- exness:鸽派决议帮助黄金反弹,焦点转向美国GDP
- Pp-yoloe details
- 12_ UE4 advanced_ Change a more beautiful character model
- Ten thousand words detailed Google play online application standard package format AAB
猜你喜欢

Example analysis of while, repeat and loop loops in MySQL process control

During the year, the first "three consecutive falls" of No. 95 gasoline returned to the "8 Yuan era"“

KNN method predicts pregnancy, KNN principle simple code

AI platform, AI midrange architecture

国产ERP有没有机会击败SAP ?

makefile详解

How to deploy sentinel cluster of redis

【C】 Array

Implement Lmax disruptor queue from scratch (VI) analysis of the principle of disruptor solving pseudo sharing and consumers' elegant stopping
![[technology 1]](/img/eb/63baf1ae3931a156a0a5b377a9b7d1.jpg)
[technology 1]
随机推荐
HDU multi School Game 2 1011 DOS card
C traps and defects Chapter 3 semantic "traps" 3.4 avoid "couple method"
Learn more than 4000 words, understand the problem of this pointing in JS, and handwrite to realize call, apply and bind
Military product development process - transition phase
ShardingSphere之水平分表实战(三)
3.2 model saving and loading
What if MySQL forgets the password
Score addition and subtraction of force deduction and brushing questions (one question per day 7/27)
Regular expression bypasses WAF
Three military product baselines (functional baseline, distribution baseline, product baseline) and the documents contained in the baseline
i. MX 8m plus integrated dedicated neural processing engine (NPU)
Simple code implementation of decision tree
C traps and defects Chapter 3 semantic "traps" 3.1 pointers and arrays
Self study notes on Apache file management -- mapping folders and configuring Apache virtual machines based on single IP and multi domain names
STC MCU drive 1.8 'TFT SPI screen demonstration example (including data package)
Whole process record of yolov3 target detection
Summarize the knowledge points of the ten JVM modules. If you don't believe it, you still don't understand it
Tonight at 7:30 | is the AI world in the eyes of Lianjie, Jiangmen, Baidu and country garden venture capital continue to be advanced or return to the essence of business
Makefile details
How to realize shortcut keys for interface scaling by vscade