aboutsummaryrefslogtreecommitdiff
path: root/src/prevector.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2018-11-12 10:41:18 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2018-11-12 13:43:56 +0100
commitae32806ea20235c4542b1a5d4011df5ae267b58a (patch)
treedd981282297fe354c4662ad456f6555b09b70fb8 /src/prevector.h
parentedc715240cb6738262ae96dea476544052eb5351 (diff)
parent76e13b586ff690dd3312f719f305c0d1021cd505 (diff)
Merge #14651: Refactor: Fix compiler warning in prevector.h
76e13b586ff690dd3312f719f305c0d1021cd505 warnings: Compiler warning on memset usage for non-trivial type (Lenny Maiorani) Pull request description: Fixing warnings reported by GCC: memset of non-trivial type Tree-SHA512: 357aeac60acfb922851daaf0bd8d4b81e377da7c9b31c2942b54cfdd4129dae61e577fc0a6aa430348cb07abd16ae32f986a64dbb2c1d90ec148f53e7451a229
Diffstat (limited to 'src/prevector.h')
-rw-r--r--src/prevector.h16
1 files changed, 3 insertions, 13 deletions
diff --git a/src/prevector.h b/src/prevector.h
index 6ddb6f321f..aa77573746 100644
--- a/src/prevector.h
+++ b/src/prevector.h
@@ -10,6 +10,7 @@
#include <stdint.h>
#include <string.h>
+#include <algorithm>
#include <cstddef>
#include <iterator>
#include <type_traits>
@@ -198,22 +199,11 @@ private:
const T* item_ptr(difference_type pos) const { return is_direct() ? direct_ptr(pos) : indirect_ptr(pos); }
void fill(T* dst, ptrdiff_t count) {
- if (IS_TRIVIALLY_CONSTRUCTIBLE<T>::value) {
- // The most common use of prevector is where T=unsigned char. For
- // trivially constructible types, we can use memset() to avoid
- // looping.
- ::memset(dst, 0, count * sizeof(T));
- } else {
- for (auto i = 0; i < count; ++i) {
- new(static_cast<void*>(dst + i)) T();
- }
- }
+ std::fill_n(dst, count, T{});
}
void fill(T* dst, ptrdiff_t count, const T& value) {
- for (auto i = 0; i < count; ++i) {
- new(static_cast<void*>(dst + i)) T(value);
- }
+ std::fill_n(dst, count, value);
}
template<typename InputIterator>