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.
This commit is contained in:
Maxime Coste 2017-08-12 22:11:58 +07:00
parent 407c84666c
commit 1b1239b25a
4 changed files with 28 additions and 12 deletions

View File

@ -21,12 +21,12 @@ enum class EolFormat
Crlf 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::Lf, "lf" },
{ EolFormat::Crlf, "crlf" }, { EolFormat::Crlf, "crlf" },
} }; });
} }
enum class ByteOrderMark enum class ByteOrderMark
@ -35,12 +35,12 @@ enum class ByteOrderMark
Utf8 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::None, "none" },
{ ByteOrderMark::Utf8, "utf8" }, { ByteOrderMark::Utf8, "utf8" },
} }; });
} }
class Buffer; class Buffer;

View File

@ -131,15 +131,15 @@ enum class Autoreload
Ask 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::Yes, "yes" },
{ Autoreload::No, "no" }, { Autoreload::No, "no" },
{ Autoreload::Ask, "ask" }, { Autoreload::Ask, "ask" },
{ Autoreload::Yes, "true" }, { Autoreload::Yes, "true" },
{ Autoreload::No, "false" } { Autoreload::No, "false" }
} }; });
} }
} }

View File

@ -136,13 +136,13 @@ enum class AutoInfo
constexpr bool with_bit_ops(Meta::Type<AutoInfo>) { return true; } 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::Command, "command"},
{ AutoInfo::OnKey, "onkey"}, { AutoInfo::OnKey, "onkey"},
{ AutoInfo::Normal, "normal" } { AutoInfo::Normal, "normal" }
} }; });
} }
bool show_auto_info_ifn(StringView title, StringView info, AutoInfo mask, const Context& context); bool show_auto_info_ifn(StringView title, StringView info, AutoInfo mask, const Context& context);

View File

@ -1,6 +1,8 @@
#ifndef meta_hh_INCLUDED #ifndef meta_hh_INCLUDED
#define meta_hh_INCLUDED #define meta_hh_INCLUDED
#include <utility>
namespace Kakoune namespace Kakoune
{ {
inline namespace Meta inline namespace Meta
@ -22,6 +24,20 @@ struct Array
T m_data[N]; 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 #endif // meta_hh_INCLUDED