diff options
| author | Maxime Coste <mawww@kakoune.org> | 2024-08-15 11:41:35 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2024-08-15 12:58:25 +1000 |
| commit | 65ac5d42c9209c4b89c590c93cfa8d985e66b168 (patch) | |
| tree | 2cf07a812c46e81c71204236b8a32c495132f62e /src | |
| parent | b804693630f61be757413e6e5a700995be1b164b (diff) | |
Remove unused ConstexprVector and rename constexpr_utils.hh to array.hh
Diffstat (limited to 'src')
| -rw-r--r-- | src/array.hh | 48 | ||||
| -rw-r--r-- | src/buffer.hh | 2 | ||||
| -rw-r--r-- | src/client.hh | 2 | ||||
| -rw-r--r-- | src/constexpr_utils.hh | 90 | ||||
| -rw-r--r-- | src/debug.hh | 2 | ||||
| -rw-r--r-- | src/file.hh | 2 | ||||
| -rw-r--r-- | src/hook_manager.hh | 2 | ||||
| -rw-r--r-- | src/input_handler.hh | 2 | ||||
| -rw-r--r-- | src/option.hh | 2 | ||||
| -rw-r--r-- | src/ranges.hh | 2 | ||||
| -rw-r--r-- | src/selectors.hh | 2 | ||||
| -rw-r--r-- | src/string_utils.hh | 2 |
12 files changed, 58 insertions, 100 deletions
diff --git a/src/array.hh b/src/array.hh new file mode 100644 index 00000000..ec8b098b --- /dev/null +++ b/src/array.hh @@ -0,0 +1,48 @@ +#ifndef array_hh_INCLUDED +#define array_hh_INCLUDED + +#include <utility> +#include <stddef.h> + +#include "array_view.hh" + +namespace Kakoune +{ + +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; } + + constexpr T& operator[](int i) { return m_data[i]; } + constexpr T* begin() { return m_data; } + constexpr T* end() { return m_data+N; } + + constexpr operator ArrayView<T>() { return {m_data, N}; } + constexpr operator ConstArrayView<T>() const { return {m_data, N}; } + + T m_data[N]; +}; + +template<typename T, typename... U> requires (std::is_same_v<T, U> and ...) +Array(T, U...) -> Array<T, 1 + sizeof...(U)>; + +template<typename T, size_t N, size_t... Indices> +constexpr Array<T, N> make_array(const 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(const T (&data)[N]) +{ + return make_array(data, std::make_index_sequence<N>()); +} + +} + +#endif // array_hh_INCLUDED diff --git a/src/buffer.hh b/src/buffer.hh index 7b671c0e..ec2b9620 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -3,7 +3,7 @@ #include "clock.hh" #include "coord.hh" -#include "constexpr_utils.hh" +#include "array.hh" #include "enum.hh" #include "file.hh" #include "optional.hh" diff --git a/src/client.hh b/src/client.hh index 64262f91..05b091ae 100644 --- a/src/client.hh +++ b/src/client.hh @@ -1,7 +1,7 @@ #ifndef client_hh_INCLUDED #define client_hh_INCLUDED -#include "constexpr_utils.hh" +#include "array.hh" #include "display_buffer.hh" #include "env_vars.hh" #include "input_handler.hh" diff --git a/src/constexpr_utils.hh b/src/constexpr_utils.hh deleted file mode 100644 index f83faacb..00000000 --- a/src/constexpr_utils.hh +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef constexpr_utils_hh_INCLUDED -#define constexpr_utils_hh_INCLUDED - -#include <utility> -#include <initializer_list> -#include <stddef.h> - -#include "array_view.hh" - -namespace Kakoune -{ - -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; } - - constexpr T& operator[](int i) { return m_data[i]; } - constexpr T* begin() { return m_data; } - constexpr T* end() { return m_data+N; } - - constexpr operator ArrayView<T>() { return {m_data, N}; } - constexpr operator ConstArrayView<T>() const { return {m_data, N}; } - - T m_data[N]; -}; - -template<typename T, typename... U> requires (std::is_same_v<T, U> and ...) -Array(T, U...) -> Array<T, 1 + sizeof...(U)>; - -template<typename T, size_t N, size_t... Indices> -constexpr Array<T, N> make_array(const 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(const T (&data)[N]) -{ - return make_array(data, std::make_index_sequence<N>()); -} - -template<typename T, size_t capacity> -struct ConstexprVector -{ - using iterator = T*; - using const_iterator = const T*; - - constexpr ConstexprVector() : m_size{0} {} - constexpr ConstexprVector(std::initializer_list<T> items) - : m_size{items.size()} - { - T* ptr = m_data; - for (auto& item : items) - *ptr++ = std::move(item); - } - - constexpr bool empty() const { return m_size == 0; } - constexpr size_t size() const { return m_size; } - - constexpr void resize(size_t n, const T& val = {}) - { - if (n >= capacity) - throw "capacity exceeded"; - for (int i = m_size; i < n; ++i) - m_data[i] = val; - m_size = n; - kak_assert(this->size() == m_size); // check for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79520 - } - - constexpr T& operator[](size_t i) { return m_data[i]; } - constexpr const T& operator[](size_t i) const { return m_data[i]; } - - constexpr iterator begin() { return m_data; } - constexpr iterator end() { return m_data + m_size; } - - constexpr const_iterator begin() const { return m_data; } - constexpr const_iterator end() const { return m_data + m_size; } - - size_t m_size; - T m_data[capacity] = {}; -}; - -} - -#endif // constexpr_utils_hh_INCLUDED diff --git a/src/debug.hh b/src/debug.hh index ec010460..723bbb9e 100644 --- a/src/debug.hh +++ b/src/debug.hh @@ -1,7 +1,7 @@ #ifndef debug_hh_INCLUDED #define debug_hh_INCLUDED -#include "constexpr_utils.hh" +#include "array.hh" #include "enum.hh" #include "flags.hh" diff --git a/src/file.hh b/src/file.hh index 9411fd78..ead88c43 100644 --- a/src/file.hh +++ b/src/file.hh @@ -6,7 +6,7 @@ #include "meta.hh" #include "string.hh" #include "units.hh" -#include "constexpr_utils.hh" +#include "array.hh" #include "vector.hh" #include <sys/types.h> diff --git a/src/hook_manager.hh b/src/hook_manager.hh index 114deefd..ee1adafb 100644 --- a/src/hook_manager.hh +++ b/src/hook_manager.hh @@ -6,7 +6,7 @@ #include "safe_ptr.hh" #include "meta.hh" #include "enum.hh" -#include "constexpr_utils.hh" +#include "array.hh" #include <memory> diff --git a/src/input_handler.hh b/src/input_handler.hh index fa7c91b1..54c5fd5b 100644 --- a/src/input_handler.hh +++ b/src/input_handler.hh @@ -2,7 +2,7 @@ #define input_handler_hh_INCLUDED #include "completion.hh" -#include "constexpr_utils.hh" +#include "array.hh" #include "context.hh" #include "env_vars.hh" #include "enum.hh" diff --git a/src/option.hh b/src/option.hh index b6edca0c..7e29deb7 100644 --- a/src/option.hh +++ b/src/option.hh @@ -4,7 +4,7 @@ #include "enum.hh" #include "meta.hh" #include "vector.hh" -#include "constexpr_utils.hh" +#include "array.hh" namespace Kakoune { diff --git a/src/ranges.hh b/src/ranges.hh index 1b6f8869..af13d6f8 100644 --- a/src/ranges.hh +++ b/src/ranges.hh @@ -6,7 +6,7 @@ #include <iterator> #include <numeric> -#include "constexpr_utils.hh" +#include "array.hh" namespace Kakoune { diff --git a/src/selectors.hh b/src/selectors.hh index e947250f..e132d897 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -6,7 +6,7 @@ #include "meta.hh" #include "unicode.hh" #include "vector.hh" -#include "constexpr_utils.hh" +#include "array.hh" namespace Kakoune { diff --git a/src/string_utils.hh b/src/string_utils.hh index 7c115269..559a6867 100644 --- a/src/string_utils.hh +++ b/src/string_utils.hh @@ -7,7 +7,7 @@ #include "optional.hh" #include "utils.hh" #include "format.hh" -#include "constexpr_utils.hh" +#include "array.hh" namespace Kakoune { |
