Jamba C++ API  6.2.0
stl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 pongasoft
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  *
16  * @author Yan Pujante
17  */
18 
19 #ifndef PONGASOFT_JAMBA_STL_H
20 #define PONGASOFT_JAMBA_STL_H
21 
22 #include <array>
23 
24 namespace pongasoft::stl {
25 
26 // Implementation
27 namespace impl {
28 template<typename T, typename U, typename F, std::size_t N, std::size_t... I>
29 constexpr std::array<U, N> transformArray(std::array<T, N> const &a, F &&f, std::index_sequence<I...>)
30 {
31  return { f(a[I])... };
32 }
33 
34 }
35 
39 template<typename T, typename U, typename F, std::size_t N, typename Indices = std::make_index_sequence<N>>
40 constexpr std::array<U, N> transform(std::array<T, N> const &a, F &&f)
41 {
42  return impl::transformArray<T, U>(a, std::forward<F>(f), Indices{});
43 }
44 
45 }
46 
47 #endif //PONGASOFT_JAMBA_STL_H
constexpr std::array< U, N > transformArray(std::array< T, N > const &a, F &&f, std::index_sequence< I... >)
Definition: stl.h:29
constexpr std::array< U, N > transform(std::array< T, N > const &a, F &&f)
Transforms an array containing elements of type T into an array containing elements of type U by appl...
Definition: stl.h:40
Definition: stl.h:24