/* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */ #ifndef MPT_BASE_ARRAY_HPP #define MPT_BASE_ARRAY_HPP #include "mpt/base/detect.hpp" #include "mpt/base/namespace.hpp" #include #include #include namespace mpt { inline namespace MPT_INLINE_NS { template struct stdarray_extent : std::integral_constant { }; template struct stdarray_extent> : std::integral_constant { }; template struct is_stdarray : std::false_type { }; template struct is_stdarray> : std::true_type { }; // mpt::extent is the same as std::extent, // but also works for std::array, // and asserts that the given type is actually an array type instead of returning 0. // use as: // mpt::extent() // mpt::extent() // mpt::extent() // mpt::extent() template constexpr std::size_t extent() noexcept { using Tarray = typename std::remove_cv::type>::type; static_assert(std::is_array::value || mpt::is_stdarray::value); if constexpr (mpt::is_stdarray::value) { return mpt::stdarray_extent(); } else { return std::extent(); } } template struct array_size; template struct array_size> { static constexpr std::size_t size = N; }; template struct array_size { static constexpr std::size_t size = N; }; template constexpr std::array init_array(const Tx & x) { std::array result{}; for (std::size_t i = 0; i < N; ++i) { result[i] = x; } return result; } } // namespace MPT_INLINE_NS } // namespace mpt #endif // MPT_BASE_ARRAY_HPP