<commit_before>/******************************************************************************
 *                       ____    _    _____                                   *
 *                      / ___|  / \  |  ___|    C++                           *
 *                     | |     / _ \ | |_       Actor                         *
 *                     | |___ / ___ \|  _|      Framework                     *
 *                      \____/_/   \_|_|                                      *
 *                                                                            *
 * Copyright 2011-2018 <NAME>                                     *
 *                                                                            *
 * 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<commit_msg>Clarify preconditions of zip_ algorithms<commit_after>/******************************************************************************
 *                       ____    _    _____                                   *
 *                      / ___|  / \  |  ___|    C++                           *
 *                     | |     / _ \ | |_       Actor                         *
 *                     | |___ / ___ \|  _|      Framework                     *
 *                      \____/_/   \_|_|                                      *
 *                                                                            *
 * Copyright 2011-2018 <NAME>                                     *
 *                                                                            *
 * 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 {

/// Like `std::for_each`, but for multiple containers.
/// @pre `x.size() <= y.size()` for each `y` in `xs`
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.
/// @pre `x.size() <= y.size()` for each `y` in `xs`
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`.
/// @relates container_view
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
{'fraction_non_alphanumeric': 0.16501887470789142, 'fraction_numerical': 0.005752291928815387, 'mean_word_length': 1.556985294117647, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6597243', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1445, 'n_words': 430}