1b1239b25a
The need to have the array size in the return type was redundant with the actual list of elements.
44 lines
938 B
C++
44 lines
938 B
C++
#ifndef meta_hh_INCLUDED
|
|
#define meta_hh_INCLUDED
|
|
|
|
#include <utility>
|
|
|
|
namespace Kakoune
|
|
{
|
|
inline namespace Meta
|
|
{
|
|
|
|
struct AnyType{};
|
|
template<typename T> struct Type : AnyType {};
|
|
|
|
}
|
|
|
|
template<typename T, size_t N>
|
|
struct Array
|
|
{
|
|
constexpr size_t size() const { return N; }
|
|
constexpr const T& operator[](int i) const { return m_data[i]; }
|
|
constexpr const T* begin() const { return m_data; }
|
|
constexpr const T* end() const { return 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
|