From 3370445a2e22ee00687ecef2e9dc88f47bb2b4c6 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 23 Dec 2023 14:42:15 +0100 Subject: a --- compat/map.hpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 compat/map.hpp (limited to 'compat') diff --git a/compat/map.hpp b/compat/map.hpp new file mode 100644 index 00000000..def97d0e --- /dev/null +++ b/compat/map.hpp @@ -0,0 +1,40 @@ +#pragma once +#include "compat/integer-types.hpp" +#include +#include +#include +#include + +namespace floormat::detail::map { + +template +CORRADE_ALWAYS_INLINE +constexpr auto map0(const std::array& array, const F& fun, std::index_sequence) +{ + return std::array { fun(array[Indexes])... }; +} + +template +[[deprecated("zero-length array!")]] +CORRADE_ALWAYS_INLINE +constexpr auto map0(const std::array&, const F& fun, std::index_sequence<>) +{ + return std::array()) )> , 0>{}; +} + +} // namespace floormat::detail::map + +namespace floormat { + +template F, size_t N> +constexpr auto map(const std::array& array, const F& fun) +{ + using return_type = std::decay_t; + static_assert(!std::is_same_v); + static_assert(std::is_same_v>); + static_assert(sizeof(return_type) > 0); + using ::floormat::detail::map::map0; + return map0(array, fun, std::make_index_sequence{}); +} + +} // namespace floormat -- cgit v1.2.3