xref: /aosp_15_r20/external/libbrillo/brillo/array_utils.h (revision 1a96fba65179ea7d3f56207137718607415c5953)
1 // Copyright 2019 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef LIBBRILLO_BRILLO_ARRAY_UTILS_H_
6 #define LIBBRILLO_BRILLO_ARRAY_UTILS_H_
7 
8 #include <array>
9 #include <utility>
10 
11 namespace brillo {
12 
13 // Create a std::array from a set of values without manually specifying the
14 // size of the array. Note that unlike the make_array likely to make its way
15 // into C++20, this function always requires the user to specify ElementType.
16 // This is done so that users are not surprised by the element type of resulting
17 // arrays when std::common_type is used.
18 template <typename ElementType, typename... T>
make_array(T &&...values)19 constexpr auto make_array(T&&... values) {
20   return std::array<ElementType, sizeof...(T)>{
21       static_cast<ElementType>(std::forward<T>(values))...};
22 }
23 
24 }  // namespace brillo
25 
26 #endif  // LIBBRILLO_BRILLO_ARRAY_UTILS_H_
27