diff --git a/src/buffer.hh b/src/buffer.hh index 7cf2db7b..4fa42d56 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -21,12 +21,12 @@ enum class EolFormat Crlf }; -constexpr Array, 2> enum_desc(Meta::Type) +constexpr auto enum_desc(Meta::Type) { - return { { + return make_array>({ { EolFormat::Lf, "lf" }, { EolFormat::Crlf, "crlf" }, - } }; + }); } enum class ByteOrderMark @@ -35,12 +35,12 @@ enum class ByteOrderMark Utf8 }; -constexpr Array, 2> enum_desc(Meta::Type) +constexpr auto enum_desc(Meta::Type) { - return { { + return make_array>({ { ByteOrderMark::None, "none" }, { ByteOrderMark::Utf8, "utf8" }, - } }; + }); } class Buffer; diff --git a/src/client.hh b/src/client.hh index 09329c6c..f65208e5 100644 --- a/src/client.hh +++ b/src/client.hh @@ -131,15 +131,15 @@ enum class Autoreload Ask }; -constexpr Array, 5> enum_desc(Meta::Type) +constexpr auto enum_desc(Meta::Type) { - return { { + return make_array>({ { Autoreload::Yes, "yes" }, { Autoreload::No, "no" }, { Autoreload::Ask, "ask" }, { Autoreload::Yes, "true" }, { Autoreload::No, "false" } - } }; + }); } } diff --git a/src/input_handler.hh b/src/input_handler.hh index 4287f172..71d93220 100644 --- a/src/input_handler.hh +++ b/src/input_handler.hh @@ -136,13 +136,13 @@ enum class AutoInfo constexpr bool with_bit_ops(Meta::Type) { return true; } -constexpr Array, 3> enum_desc(Meta::Type) +constexpr auto enum_desc(Meta::Type) { - return { { + return make_array>({ { AutoInfo::Command, "command"}, { AutoInfo::OnKey, "onkey"}, { AutoInfo::Normal, "normal" } - } }; + }); } bool show_auto_info_ifn(StringView title, StringView info, AutoInfo mask, const Context& context); diff --git a/src/meta.hh b/src/meta.hh index 04c343d5..2a1c9d01 100644 --- a/src/meta.hh +++ b/src/meta.hh @@ -1,6 +1,8 @@ #ifndef meta_hh_INCLUDED #define meta_hh_INCLUDED +#include + namespace Kakoune { inline namespace Meta @@ -22,6 +24,20 @@ struct Array T m_data[N]; }; +template +constexpr Array make_array(T (&&data)[N], std::index_sequence) +{ + static_assert(sizeof...(Indices) == N, "size mismatch"); + return {{data[Indices]...}}; +} + +template +constexpr Array make_array(T (&&data)[N]) +{ + return make_array(std::forward(data), + std::make_index_sequence()); +} + } #endif // meta_hh_INCLUDED