Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F73240481
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
Fri, Jul 19, 22:22
Size
480 B
Mime Type
text/x-c
Expires
Sun, Jul 21, 22:22 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
19162311
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