From 6cd8acab3081edde04a0b77a8ceb5438eb478227 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 17 Jan 2015 18:31:42 +0000 Subject: [PATCH] Refactor ntstring forwarding --- common/include/ntstring.h | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/common/include/ntstring.h b/common/include/ntstring.h index 336971ae1..e9d66ea10 100644 --- a/common/include/ntstring.h +++ b/common/include/ntstring.h @@ -28,43 +28,44 @@ public: std::fill(oc, this->end(), 0); return r; } - template - bool _copy(const char *i) - { - return _copy(0, i); - } template bool _copy(std::size_t offset, const char *i) { static_assert(N <= L, "string too long"); return _copy_n(offset, i, N); } - template - void copy_if(const ntstring &, std::size_t = 0) = delete; + template + bool copy_if(I &&i) + { + return copy_if(static_cast(0), static_cast(i)); + } + template + bool copy_if(I &&i, std::size_t N) + { + return copy_if(static_cast(0), static_cast(i), N); + } + template + bool copy_if(std::size_t out_offset, I &&i) + { + return copy_if(out_offset, static_cast(i), this->size()); + } template void copy_if(std::size_t, const ntstring &, std::size_t = 0) = delete; template - bool copy_if(const array &i, std::size_t n = N) + bool copy_if(std::size_t out_offset, const array &i, std::size_t n = N) { #ifdef DXX_HAVE_BUILTIN_CONSTANT_P if (__builtin_constant_p(n > N) && n > N) DXX_ALWAYS_ERROR_FUNCTION(dxx_trap_overread, "read size exceeds array size"); #endif - return copy_if(i.data(), n); + return copy_if(out_offset, i.data(), n); } template - bool copy_if(const char (&i)[N]) + bool copy_if(std::size_t out_offset, const char (&i)[N]) { -#ifdef DXX_HAVE_BUILTIN_CONSTANT_P - if (__builtin_constant_p(i[N - 1]) && !i[N - 1]) - return _copy(i); -#endif - return copy_if(i, N); + static_assert(N <= L + 1, "string too long"); + return copy_if(out_offset, i, N); } - bool copy_if(const char *i, std::size_t N = L + 1) - { - return copy_if(0, i, N); - } bool copy_if(std::size_t offset, const char *i, std::size_t N) { const std::size_t d = @@ -92,7 +93,6 @@ public: template ntstring &operator=(const char (&i)[N]) { - static_assert(N <= L + 1, "string too long"); copy_if(i); return *this; }