#ifndef BOOST_COMPAT_TO_ARRAY_HPP_INCLUDED #define BOOST_COMPAT_TO_ARRAY_HPP_INCLUDED // Copyright 2024 Ruben Perez Hidalgo // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt #include #include #include #include #include #include namespace boost { namespace compat { namespace detail { template constexpr std::array, N> to_array_lvalue(T (&a)[N], index_sequence) { return {{a[I]...}}; } template constexpr std::array, N> to_array_rvalue(T (&&a)[N], index_sequence) { return {{std::move(a[I])...}}; } } // namespace detail template constexpr std::array, N> to_array(T (&a)[N]) { static_assert( std::is_constructible, T&>::value, "This overload requires the resulting element type to be constructible from T&" ); static_assert(!std::is_array::value, "to_array does not work for multi-dimensional C arrays"); return detail::to_array_lvalue(a, make_index_sequence{}); } template constexpr std::array, N> to_array(T (&&a)[N]) { static_assert( std::is_constructible, T&&>::value, "This overload requires the resulting element type to be constructible from T&&" ); static_assert(!std::is_array::value, "to_array does not work for multi-dimensional C arrays"); return detail::to_array_rvalue(static_cast(a), make_index_sequence{}); } } // namespace compat } // namespace boost #endif // BOOST_COMPAT_TO_ARRAY_HPP_INCLUDED