Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90357045
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
Thu, Oct 31, 22:25
Size
480 B
Mime Type
text/x-c
Expires
Sat, Nov 2, 22:25 (2 d)
Engine
blob
Format
Raw Data
Handle
22059828
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