CPP07
1.0
読み取り中…
検索中…
一致する文字列を見つけられません
iter.hpp
[詳解]
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* iter.hpp :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2025/08/07 22:22:17 by kamitsui #+# #+# */
9
/* Updated: 2025/08/07 22:31:20 by kamitsui ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
18
#ifndef ITER_HPP
19
#define ITER_HPP
20
21
#include <
cstddef
>
// For size_t
22
#include <
iostream
>
// For std::cout in helper function
23
32
template
<
typename
T>
void
iter
(
T
*array,
size_t
length,
void
(*
f
)(
T
&)) {
33
if
(!array || !
f
) {
34
return
;
35
}
36
for
(
size_t
i
= 0;
i
< length; ++
i
) {
37
f
(array[
i
]);
38
}
39
}
40
49
template
<
typename
T>
void
iter
(
const
T
*array,
size_t
length,
void
(*
f
)(
const
T
&)) {
50
if
(!array || !
f
) {
51
return
;
52
}
53
for
(
size_t
i
= 0;
i
< length; ++
i
) {
54
f
(array[
i
]);
55
}
56
}
57
58
// --- Helper function templates for standard output. ---
59
65
template
<
typename
T>
void
printElement
(
const
T
&
element
) {
std::cout
<<
element
<<
" "
; }
66
72
template
<
typename
T>
void
incrementElement
(
T
&
element
) {
element
++; }
73
74
#endif
std::cout
cstddef
iostream
incrementElement
void incrementElement(T &element)
Increments a numeric element.
Definition
iter.hpp:72
printElement
void printElement(const T &element)
Prints an element to the standard output.
Definition
iter.hpp:65
iter
void iter(T *array, size_t length, void(*f)(T &))
Applies a function to each element of an array. This version is for non-const arrays and allows modif...
Definition
iter.hpp:32
ex01
iter.hpp
構築:
1.9.8