tenno 0.1.0
Loading...
Searching...
No Matches
algorithm.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#include <tenno/utility.hpp>
9
10namespace tenno
11{
12
27template <typename InputIt, typename OutputIt>
28constexpr OutputIt copy(InputIt first, InputIt last, OutputIt d_first)
29{
30 while (first != last)
31 {
32 // *d_first++ = *first++;
33 *d_first = *first;
34 d_first++;
35 first++;
36 }
37 return d_first;
38}
39
55template <class InputIt, class UnaryFunc>
56constexpr UnaryFunc for_each(InputIt first, InputIt last, UnaryFunc f)
57{
58 while (first != last)
59 {
60 f(*first++);
61 }
62 return f;
63}
64
82template <class InputIt, class T>
83constexpr T accumulate(InputIt first, InputIt last, T init) noexcept
84{
85 while (first != last)
86 {
87 init += *first++;
88 }
89 return init;
90}
91
99template <class T> void swap(T &a, T &b) noexcept
100{
101 T tmp = tenno::move(a);
102 a = tenno::move(b);
103 b = tenno::move(tmp);
104}
105
106} // namespace tenno
constexpr T accumulate(InputIt first, InputIt last, T init) noexcept
Applies the given function f to the result of dereferencing every element in the range [first,...
Definition algorithm.hpp:83
constexpr UnaryFunc for_each(InputIt first, InputIt last, UnaryFunc f)
Applies the given function f to the result of dereferencing every element in the range [first,...
Definition algorithm.hpp:56
constexpr OutputIt copy(InputIt first, InputIt last, OutputIt d_first)
Copies the elements in the range [first, last) to the range beginning at d_first.
Definition algorithm.hpp:28
constexpr std::remove_reference_t< T > && move(T &&t) noexcept
Move a value from one location to another.
Definition utility.hpp:21
void swap(T &a, T &b) noexcept
Exchanges the values of a and b.
Definition algorithm.hpp:99