|
21 | 21 |
|
22 | 22 | #include <cstddef> |
23 | 23 |
|
24 | | -namespace el { |
25 | | - namespace array { |
| 24 | +namespace el::array { |
26 | 25 |
|
27 | | - /** |
28 | | - * Return a pointer to the last element of a nullptr terminated array. |
29 | | - * |
30 | | - * @param it the input array to count, |
31 | | - * @return the pointer which points the nullptr. |
32 | | - */ |
33 | | - template <typename T> |
34 | | - constexpr T* end(T* it) noexcept |
35 | | - { |
36 | | - if (it == nullptr) |
37 | | - return nullptr; |
| 26 | + /** |
| 27 | + * Return a pointer to the last element of a nullptr terminated array. |
| 28 | + * |
| 29 | + * @param it the input array to count, |
| 30 | + * @return the pointer which points the nullptr. |
| 31 | + */ |
| 32 | + template <typename T> |
| 33 | + constexpr T* end(T* it) noexcept |
| 34 | + { |
| 35 | + if (it == nullptr) |
| 36 | + return nullptr; |
38 | 37 |
|
39 | | - while (*it != 0) |
40 | | - ++it; |
41 | | - return it; |
42 | | - } |
| 38 | + while (*it != 0) |
| 39 | + ++it; |
| 40 | + return it; |
| 41 | + } |
43 | 42 |
|
44 | | - /** |
45 | | - * Return the size of a nullptr terminated array. |
46 | | - * |
47 | | - * @param begin the input array to count, |
48 | | - * @return the size of the array. |
49 | | - */ |
50 | | - template <typename T> |
51 | | - constexpr size_t length(T* const begin) noexcept |
52 | | - { |
53 | | - return end(begin) - begin; |
54 | | - } |
| 43 | + /** |
| 44 | + * Return the size of a nullptr terminated array. |
| 45 | + * |
| 46 | + * @param begin the input array to count, |
| 47 | + * @return the size of the array. |
| 48 | + */ |
| 49 | + template <typename T> |
| 50 | + constexpr size_t length(T* const begin) noexcept |
| 51 | + { |
| 52 | + return end(begin) - begin; |
| 53 | + } |
55 | 54 |
|
56 | | - /** |
57 | | - * Re-implementation of std::copy to avoid `memmove` symbol. |
58 | | - * |
59 | | - * @tparam I input type |
60 | | - * @tparam O output type |
61 | | - * @param src_begin |
62 | | - * @param src_end |
63 | | - * @param dst_begin |
64 | | - * @param dst_end |
65 | | - * @return output iterator to the last copied element. |
66 | | - */ |
67 | | - template <typename I, typename O> |
68 | | - constexpr O* copy(I* const src_begin, I* const src_end, |
69 | | - O* const dst_begin, O* const dst_end) noexcept |
70 | | - { |
71 | | - auto src_it = src_begin; |
72 | | - auto dst_it = dst_begin; |
73 | | - for (; src_it != src_end && dst_it != dst_end;) |
74 | | - *dst_it++ = *src_it++; |
| 55 | + /** |
| 56 | + * Re-implementation of std::copy to avoid `memmove` symbol. |
| 57 | + * |
| 58 | + * @tparam I input type |
| 59 | + * @tparam O output type |
| 60 | + * @param src_begin |
| 61 | + * @param src_end |
| 62 | + * @param dst_begin |
| 63 | + * @param dst_end |
| 64 | + * @return output iterator to the last copied element. |
| 65 | + */ |
| 66 | + template <typename I, typename O> |
| 67 | + constexpr O* copy(I* const src_begin, I* const src_end, |
| 68 | + O* const dst_begin, O* const dst_end) noexcept |
| 69 | + { |
| 70 | + auto src_it = src_begin; |
| 71 | + auto dst_it = dst_begin; |
| 72 | + for (; src_it != src_end && dst_it != dst_end;) |
| 73 | + *dst_it++ = *src_it++; |
75 | 74 |
|
76 | | - return (src_it == src_end) ? dst_it : nullptr; |
77 | | - } |
| 75 | + return (src_it == src_end) ? dst_it : nullptr; |
| 76 | + } |
78 | 77 |
|
79 | | - /** |
80 | | - * Check if two nullptr terminated array is equal till the limit. |
81 | | - * |
82 | | - * @tparam T |
83 | | - * @param lhs |
84 | | - * @param rhs |
85 | | - * @param length |
86 | | - * @return true if the two array is equal till the limit. |
87 | | - */ |
88 | | - template <typename T> |
89 | | - constexpr bool equal_n(T* const lhs, T* const rhs, const size_t length) noexcept |
90 | | - { |
91 | | - for (size_t idx = 0; idx < length; ++idx) { |
92 | | - if (lhs[idx] != rhs[idx]) |
93 | | - return false; |
94 | | - } |
95 | | - return true; |
| 78 | + /** |
| 79 | + * Check if two nullptr terminated array is equal till the limit. |
| 80 | + * |
| 81 | + * @tparam T |
| 82 | + * @param lhs |
| 83 | + * @param rhs |
| 84 | + * @param length |
| 85 | + * @return true if the two array is equal till the limit. |
| 86 | + */ |
| 87 | + template <typename T> |
| 88 | + constexpr bool equal_n(T* const lhs, T* const rhs, const size_t length) noexcept |
| 89 | + { |
| 90 | + for (size_t idx = 0; idx < length; ++idx) { |
| 91 | + if (lhs[idx] != rhs[idx]) |
| 92 | + return false; |
96 | 93 | } |
| 94 | + return true; |
97 | 95 | } |
98 | 96 | } |
0 commit comments