Version: SMASH-3.1
algorithms.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2015,2017-2018,2020
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_ALGORITHMS_H_
11 #define SRC_INCLUDE_SMASH_ALGORITHMS_H_
12 
13 #include <algorithm>
14 #include <cmath>
15 #include <utility>
16 
32 namespace smash {
33 
52 template <typename Iterator>
54  Iterator begin, const Iterator &end,
55  typename std::iterator_traits<Iterator>::value_type length) {
56  bool had_to_wrap = false;
57  for (; begin != end; ++begin) {
58  auto &x = *begin;
59  if (x < 0) {
60  had_to_wrap = true;
61  x += length;
62  } else if (x >= length) {
63  had_to_wrap = true;
64  x -= length;
65  }
66  }
67  return had_to_wrap;
68 }
69 
79 template <typename Container, typename UnaryPredicate>
80 inline bool all_of(Container &&c, UnaryPredicate &&p) {
81  return std::all_of(std::begin(c), std::end(c),
82  std::forward<UnaryPredicate>(p));
83 }
84 
95 template <typename Container, typename UnaryFunction>
96 inline UnaryFunction for_each(Container &&c, UnaryFunction &&f) {
97  return std::for_each(std::begin(c), std::end(c),
98  std::forward<UnaryFunction>(f));
99 }
100 
101 } // namespace smash
102 
103 #endif // SRC_INCLUDE_SMASH_ALGORITHMS_H_
constexpr int p
Proton.
Definition: action.h:24
UnaryFunction for_each(Container &&c, UnaryFunction &&f)
Convenience wrapper for std::for_each that operates on a complete container.
Definition: algorithms.h:96
static bool enforce_periodic_boundaries(Iterator begin, const Iterator &end, typename std::iterator_traits< Iterator >::value_type length)
Enforces periodic boundaries on the given collection of values.
Definition: algorithms.h:53
bool all_of(Container &&c, UnaryPredicate &&p)
Convenience wrapper for std::all_of that operates on a complete container.
Definition: algorithms.h:80