Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78333975
for_each.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Aug 19, 21:34
Size
480 B
Mime Type
text/x-c
Expires
Wed, Aug 21, 21:34 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20024282
Attached To
R7571 SP4E-TB-TL-FR
for_each.cpp
View Options
#include <algorithm>
#include <iostream>
#include <vector>
int
main
()
{
std
::
vector
<
int
>
vec
(
10
);
// indirect call
auto
foo
=
[](
auto
&
v
)
{
std
::
cout
<<
v
;
};
std
::
for_each
(
vec
.
begin
(),
vec
.
end
(),
foo
);
// inline call
std
::
for_each
(
vec
.
begin
(),
vec
.
end
(),
[](
auto
&
v
)
{
v
+=
1
;
});
// storing result in another array
std
::
vector
<
int
>
res
;
std
::
transform
(
vec
.
begin
(),
vec
.
end
(),
std
::
back_inserter
(
res
),
[](
auto
&
val
)
{
return
val
+
1
;
});
}
Event Timeline
Log In to Comment