diff options
author | John Ankarström <john@ankarstrom.se> | 2022-09-07 23:33:08 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-09-07 23:33:08 +0200 |
commit | b5917be252caf9d38ae9466352c4176ef25732e3 (patch) | |
tree | 8eee2398b84cd533999a6d6f7539131daef5acfd /c/util.h | |
parent | ac7d676a1c457f71f1d3ae17d74699dd95c9c985 (diff) | |
download | EpisodeBrowser-b5917be252caf9d38ae9466352c4176ef25732e3.tar.gz |
Simplify Err message format.
Diffstat (limited to 'c/util.h')
-rw-r--r-- | c/util.h | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -112,11 +112,19 @@ struct UniqueOk template <typename T> struct Buf { + using U = std::remove_const_t<T>; + T* data; size_t c; + Buf(T* data, size_t c) noexcept : data(data), c(c) {} - Buf(std::basic_string<T>& s) noexcept : data(s.data()), c(s.capacity()) {} - template <size_t N> Buf(T (&data)[N]) noexcept : data(data), c(N) {} + Buf(std::enable_if<!std::is_same_v<T, U>, U*> data, size_t c) noexcept + : data(data), c(c) {} + + Buf(std::basic_string<U>& s) noexcept : data(s.data()), c(s.capacity()+1) {} + + template <size_t N> inline Buf(T (&data)[N]) noexcept : data(data), c(N) {} + operator T*() const noexcept { return data; } T& operator *() const noexcept { return *data; } T& operator [](size_t i) const noexcept { return data[i]; } @@ -142,6 +150,12 @@ inline size_t Len(T (&)[N]) return N-1; } +template <typename T> +inline size_t Len(Buf<T> buf) +{ + return buf.c-1; +} + /* Format wide string. */ template<typename... T> inline std::enable_if_t<!std::disjunction_v<std::is_class<T>...>, int> |