forked from blender/blender
main sync #3
@ -156,7 +156,29 @@ template<size_t Size, size_t Alignment> class AlignedBuffer {
|
||||
*/
|
||||
template<typename T, int64_t Size = 1> class TypedBuffer {
|
||||
private:
|
||||
BLI_NO_UNIQUE_ADDRESS AlignedBuffer<sizeof(T) * size_t(Size), alignof(T)> buffer_;
|
||||
/** Required so that `sizeof(T)` is not required when `Size` is 0. */
|
||||
static constexpr size_t get_size()
|
||||
{
|
||||
if constexpr (Size == 0) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return sizeof(T) * size_t(Size);
|
||||
}
|
||||
}
|
||||
|
||||
/** Required so that `alignof(T)` is not required when `Size` is 0. */
|
||||
static constexpr size_t get_alignment()
|
||||
{
|
||||
if constexpr (Size == 0) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return alignof(T);
|
||||
}
|
||||
}
|
||||
|
||||
BLI_NO_UNIQUE_ADDRESS AlignedBuffer<get_size(), get_alignment()> buffer_;
|
||||
|
||||
public:
|
||||
operator T *()
|
||||
|
@ -108,6 +108,16 @@ class Vector {
|
||||
template<typename OtherT, int64_t OtherInlineBufferCapacity, typename OtherAllocator>
|
||||
friend class Vector;
|
||||
|
||||
/** Required in case `T` is an incomplete type. */
|
||||
static constexpr bool is_nothrow_move_constructible()
|
||||
{
|
||||
if constexpr (InlineBufferCapacity == 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return std::is_nothrow_move_constructible_v<T>;
|
||||
}
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* Create an empty vector.
|
||||
@ -234,7 +244,7 @@ class Vector {
|
||||
*/
|
||||
template<int64_t OtherInlineBufferCapacity>
|
||||
Vector(Vector<T, OtherInlineBufferCapacity, Allocator> &&other) noexcept(
|
||||
std::is_nothrow_move_constructible_v<T>)
|
||||
is_nothrow_move_constructible())
|
||||
: Vector(NoExceptConstructor(), other.allocator_)
|
||||
{
|
||||
const int64_t size = other.size();
|
||||
|
@ -859,4 +859,14 @@ TEST(vector, RemoveChunkExceptions)
|
||||
EXPECT_EQ(vec.size(), 7);
|
||||
}
|
||||
|
||||
struct RecursiveType {
|
||||
Vector<RecursiveType, 0> my_vector;
|
||||
};
|
||||
|
||||
TEST(vector, RecursiveStructure)
|
||||
{
|
||||
RecursiveType my_recursive_type;
|
||||
my_recursive_type.my_vector.append({});
|
||||
}
|
||||
|
||||
} // namespace blender::tests
|
||||
|
Loading…
Reference in New Issue
Block a user