diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-08-12 22:11:58 +0700 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-08-12 22:11:58 +0700 |
| commit | 1b1239b25a0b3d6186d1de1f72837cc4a307e70d (patch) | |
| tree | 55caef377372cc92bfb66ceaae16a9162df49052 /src | |
| parent | 407c84666cf0d94148ded5f6c2ea6a44fa27acfc (diff) | |
Remove size redundancy in enum_desc function declaration
The need to have the array size in the return type was redundant with
the actual list of elements.
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer.hh | 12 | ||||
| -rw-r--r-- | src/client.hh | 6 | ||||
| -rw-r--r-- | src/input_handler.hh | 6 | ||||
| -rw-r--r-- | src/meta.hh | 16 |
4 files changed, 28 insertions, 12 deletions
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<EnumDesc<EolFormat>, 2> enum_desc(Meta::Type<EolFormat>) +constexpr auto enum_desc(Meta::Type<EolFormat>) { - return { { + return make_array<EnumDesc<EolFormat>>({ { EolFormat::Lf, "lf" }, { EolFormat::Crlf, "crlf" }, - } }; + }); } enum class ByteOrderMark @@ -35,12 +35,12 @@ enum class ByteOrderMark Utf8 }; -constexpr Array<EnumDesc<ByteOrderMark>, 2> enum_desc(Meta::Type<ByteOrderMark>) +constexpr auto enum_desc(Meta::Type<ByteOrderMark>) { - return { { + return make_array<EnumDesc<ByteOrderMark>>({ { 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<EnumDesc<Autoreload>, 5> enum_desc(Meta::Type<Autoreload>) +constexpr auto enum_desc(Meta::Type<Autoreload>) { - return { { + return make_array<EnumDesc<Autoreload>>({ { 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<AutoInfo>) { return true; } -constexpr Array<EnumDesc<AutoInfo>, 3> enum_desc(Meta::Type<AutoInfo>) +constexpr auto enum_desc(Meta::Type<AutoInfo>) { - return { { + return make_array<EnumDesc<AutoInfo>>({ { 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 <utility> + namespace Kakoune { inline namespace Meta @@ -22,6 +24,20 @@ struct Array T m_data[N]; }; +template<typename T, size_t N, size_t... Indices> +constexpr Array<T, N> make_array(T (&&data)[N], std::index_sequence<Indices...>) +{ + static_assert(sizeof...(Indices) == N, "size mismatch"); + return {{data[Indices]...}}; +} + +template<typename T, size_t N> +constexpr Array<T, N> make_array(T (&&data)[N]) +{ + return make_array(std::forward<decltype(data)>(data), + std::make_index_sequence<N>()); +} + } #endif // meta_hh_INCLUDED |
