Refactor ntstring forwarding

This commit is contained in:
Kp 2015-01-17 18:31:42 +00:00
parent 5eb0c0cdf9
commit 6cd8acab30

View file

@ -28,43 +28,44 @@ public:
std::fill(oc, this->end(), 0);
return r;
}
template <std::size_t N>
bool _copy(const char *i)
{
return _copy<N>(0, i);
}
template <std::size_t N>
bool _copy(std::size_t offset, const char *i)
{
static_assert(N <= L, "string too long");
return _copy_n(offset, i, N);
}
template <std::size_t N>
void copy_if(const ntstring<N> &, std::size_t = 0) = delete;
template <typename I>
bool copy_if(I &&i)
{
return copy_if(static_cast<std::size_t>(0), static_cast<I &&>(i));
}
template <typename I>
bool copy_if(I &&i, std::size_t N)
{
return copy_if(static_cast<std::size_t>(0), static_cast<I &&>(i), N);
}
template <typename I>
bool copy_if(std::size_t out_offset, I &&i)
{
return copy_if(out_offset, static_cast<I &&>(i), this->size());
}
template <std::size_t N>
void copy_if(std::size_t, const ntstring<N> &, std::size_t = 0) = delete;
template <std::size_t N>
bool copy_if(const array<char, N> &i, std::size_t n = N)
bool copy_if(std::size_t out_offset, const array<char, N> &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 <std::size_t N>
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<N - 1>(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 <std::size_t N>
ntstring &operator=(const char (&i)[N])
{
static_assert(N <= L + 1, "string too long");
copy_if(i);
return *this;
}