Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
6f368508
Commit
6f368508
authored
Feb 28, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add zipping for_each and fold algorithms
parent
441d6a0f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
+69
-0
libcaf_core/caf/detail/algorithms.hpp
libcaf_core/caf/detail/algorithms.hpp
+69
-0
No files found.
libcaf_core/caf/detail/algorithms.hpp
0 → 100644
View file @
6f368508
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_DETAIL_ALGORITHMS_HPP
#define CAF_DETAIL_ALGORITHMS_HPP
#include <vector>
#include "caf/detail/type_traits.hpp"
namespace
caf
{
namespace
detail
{
/// Calls `f` for all elements in the given containers. Behavior is undefined
/// for containers of different sizes.
/// @pre All containers have the same size.
template
<
class
F
,
class
Container
,
class
...
Containers
>
void
zip_foreach
(
F
f
,
Container
&&
x
,
Containers
&&
...
xs
)
{
for
(
size_t
i
=
0
;
i
<
x
.
size
();
++
i
)
f
(
x
[
i
],
xs
[
i
]...);
}
/// Like `std::accumulate`, but for multiple containers of equal size.
template
<
class
F
,
class
T
,
class
Container
,
class
...
Containers
>
T
zip_fold
(
F
f
,
T
init
,
Container
&&
x
,
Containers
&&
...
xs
)
{
for
(
size_t
i
=
0
;
i
<
x
.
size
();
++
i
)
init
=
f
(
init
,
x
[
i
],
xs
[
i
]...);
return
init
;
}
/// Decorates a container of type `T` to appear as container of type `U`.
template
<
class
F
,
class
Container
>
struct
container_view
{
Container
&
x
;
using
value_type
=
typename
detail
::
get_callable_trait
<
F
>::
result_type
;
inline
size_t
size
()
const
{
return
x
.
size
();
}
value_type
operator
[](
size_t
i
)
{
F
f
;
return
f
(
x
[
i
]);
}
};
/// Returns a container view for `x`.
template
<
class
F
,
class
Container
>
container_view
<
F
,
Container
>
make_container_view
(
Container
&
x
)
{
return
{
x
};
}
}
// namespace detail
}
// namespace caf
#endif // CAF_DETAIL_ALGORITHMS_HPP
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment