main sync #3

Merged
Patrick Busch merged 318 commits from blender/blender:main into main 2023-03-17 15:52:21 +01:00
3 changed files with 44 additions and 2 deletions
Showing only changes of commit 34f3893831 - Show all commits

View File

@ -156,7 +156,29 @@ template<size_t Size, size_t Alignment> class AlignedBuffer {
*/ */
template<typename T, int64_t Size = 1> class TypedBuffer { template<typename T, int64_t Size = 1> class TypedBuffer {
private: 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: public:
operator T *() operator T *()

View File

@ -108,6 +108,16 @@ class Vector {
template<typename OtherT, int64_t OtherInlineBufferCapacity, typename OtherAllocator> template<typename OtherT, int64_t OtherInlineBufferCapacity, typename OtherAllocator>
friend class Vector; 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: public:
/** /**
* Create an empty vector. * Create an empty vector.
@ -234,7 +244,7 @@ class Vector {
*/ */
template<int64_t OtherInlineBufferCapacity> template<int64_t OtherInlineBufferCapacity>
Vector(Vector<T, OtherInlineBufferCapacity, Allocator> &&other) noexcept( Vector(Vector<T, OtherInlineBufferCapacity, Allocator> &&other) noexcept(
std::is_nothrow_move_constructible_v<T>) is_nothrow_move_constructible())
: Vector(NoExceptConstructor(), other.allocator_) : Vector(NoExceptConstructor(), other.allocator_)
{ {
const int64_t size = other.size(); const int64_t size = other.size();

View File

@ -859,4 +859,14 @@ TEST(vector, RemoveChunkExceptions)
EXPECT_EQ(vec.size(), 7); 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 } // namespace blender::tests