From b5917be252caf9d38ae9466352c4176ef25732e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 7 Sep 2022 23:33:08 +0200 Subject: Simplify Err message format. --- c/util.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'c/util.h') diff --git a/c/util.h b/c/util.h index 561e232..d214f9c 100644 --- a/c/util.h +++ b/c/util.h @@ -112,11 +112,19 @@ struct UniqueOk template struct Buf { + using U = std::remove_const_t; + T* data; size_t c; + Buf(T* data, size_t c) noexcept : data(data), c(c) {} - Buf(std::basic_string& s) noexcept : data(s.data()), c(s.capacity()) {} - template Buf(T (&data)[N]) noexcept : data(data), c(N) {} + Buf(std::enable_if, U*> data, size_t c) noexcept + : data(data), c(c) {} + + Buf(std::basic_string& s) noexcept : data(s.data()), c(s.capacity()+1) {} + + template 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 +inline size_t Len(Buf buf) +{ + return buf.c-1; +} + /* Format wide string. */ template inline std::enable_if_t...>, int> -- cgit v1.2.3