Skip to content

Commit

Permalink
Merge pull request #2516 from div72/port_pr_24962
Browse files Browse the repository at this point in the history
prevector: enforce is_trivially_copyable_v
  • Loading branch information
jamescowens committed May 19, 2022
2 parents c55b616 + 6e51fd8 commit 5084080
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/prevector.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
*/
template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
class prevector {
static_assert(std::is_trivially_copyable_v<T>);

public:
typedef Size size_type;
typedef Diff difference_type;
Expand Down Expand Up @@ -411,15 +413,7 @@ class prevector {
// representation (with capacity N and size <= N).
iterator p = first;
char* endp = (char*)&(*end());
if (!std::is_trivially_destructible<T>::value) {
while (p != last) {
(*p).~T();
_size--;
++p;
}
} else {
_size -= last - p;
}
_size -= last - p;
memmove(&(*first), &(*last), endp - ((char*)(&(*last))));
return first;
}
Expand Down Expand Up @@ -464,9 +458,6 @@ class prevector {
}

~prevector() {
if (!std::is_trivially_destructible<T>::value) {
clear();
}
if (!is_direct()) {
free(_union.indirect_contents.indirect);
_union.indirect_contents.indirect = nullptr;
Expand Down

0 comments on commit 5084080

Please sign in to comment.