Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F121609147
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
Sat, Jul 12, 10:29
Size
480 B
Mime Type
text/x-c
Expires
Mon, Jul 14, 10:29 (2 d)
Engine
blob
Format
Raw Data
Handle
27344130
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