mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-21 03:31:40 +00:00
COMMON: Allow construction of Arrays of non-copyable members
Although the previous count-constructor would never make a copy of a member at runtime, Array<T>::reserve *may* copy-construct, so the compiler would forbid creation of arrays of NonCopyable objects even when the array was created only once and then never resized (and thus never actually tried to perform a copy-construction).
This commit is contained in:
parent
79dd02373c
commit
f037d4df16
@ -63,9 +63,10 @@ public:
|
||||
* Constructs an array with `count` default-inserted instances of T. No
|
||||
* copies are made.
|
||||
*/
|
||||
explicit Array(size_type count) : _size(0) {
|
||||
explicit Array(size_type count) : _size(count) {
|
||||
allocCapacity(count);
|
||||
resize(count);
|
||||
for (size_type i = 0; i < count; ++i)
|
||||
new ((void *)&_storage[i]) T();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/noncopyable.h"
|
||||
#include "common/str.h"
|
||||
|
||||
class ArrayTestSuite : public CxxTest::TestSuite
|
||||
@ -315,6 +316,10 @@ class ArrayTestSuite : public CxxTest::TestSuite
|
||||
TS_ASSERT_EQUALS(array.size(), 10U);
|
||||
TS_ASSERT_EQUALS(array[0], 0);
|
||||
TS_ASSERT_EQUALS(array[9], 0);
|
||||
|
||||
// This will fail at compile time if it is not possible to construct an
|
||||
// array without copy-construction
|
||||
Common::Array<Common::NonCopyable> nonCopyable(1);
|
||||
}
|
||||
|
||||
void test_array_constructor_count_copy_value() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user