VCCC  2024.05
VisualCamp Common C++ library
to_array.hpp
Go to the documentation of this file.
1 //
2 // Created by YongGyu Lee on 4/11/24.
3 //
4 
5 #ifndef VCCC_ARRAY_TO_ARRAY_HPP_
6 #define VCCC_ARRAY_TO_ARRAY_HPP_
7 
8 #include <array>
9 #include <cstddef>
10 #include <type_traits>
11 #include <utility>
12 
13 namespace vccc {
14 namespace detail {
15 
16 template<typename T, std::size_t N, std::size_t... I>
17 constexpr std::array<std::remove_cv_t<T>, N> to_array_impl(T (&a)[N], std::index_sequence<I...>) {
18  return {{a[I]...}};
19 }
20 
21 template<typename T, std::size_t N, std::size_t... I>
22 constexpr std::array<std::remove_cv_t<T>, N> to_array_impl(T (&&a)[N], std::index_sequence<I...>) {
23  return {{std::move(a[I])...}};
24 }
25 
26 } // namespace detail
27 
30 
32 constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&a)[N]) {
33  return vccc::detail::to_array_impl(a, std::make_index_sequence<N>{});
34 }
35 
37 constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&&a)[N]) {
38  return vccc::detail::to_array_impl(std::move(a), std::make_index_sequence<N>{});
39 }
40 
42 
43 } // namespace vccc
44 
45 #endif // VCCC_ARRAY_TO_ARRAY_HPP_
constexpr std::array< std::remove_cv_t< T >, N > to_array(T(&a)[N])
Definition: to_array.hpp:32
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35