Skip to content

Commit

Permalink
[inplace_vector] Fix a compile error in the copy constructor(!)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quuxplusone committed Oct 20, 2023
1 parent cdbfe3d commit 2ee020a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/sg14/inplace_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct SG14_INPLACE_VECTOR_TRIVIALLY_RELOCATABLE_IF(std::is_trivially_relocatabl
if constexpr (std::is_trivially_copy_constructible_v<T>) {
std::memmove(this, std::addressof(rhs), sizeof(ipvbase));
} else {
std::uninitialized_copy_n(rhs.data_, rhs.data_ + rhs.size_, data_);
std::uninitialized_copy_n(rhs.data_, rhs.size_, data_);
size_ = rhs.size_;
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/inplace_vector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,32 @@ TEST(inplace_vector, ConstructorsThrow)
}
}

TEST(inplace_vector, Copying)
{
{
using V = sg14::inplace_vector<int, 5>;
V source = {1,2,3};
V dest = source;
EXPECT_EQ(dest, (V{1,2,3}));
dest = {4,5};
EXPECT_EQ(dest, (V{4,5}));
dest = source;
EXPECT_EQ(dest, (V{1,2,3}));
EXPECT_EQ(source, (V{1,2,3}));
}
{
using V = sg14::inplace_vector<std::string, 5>;
V source = {"1", "2", "3"};
V dest = source;
EXPECT_EQ(dest, Seq("1", "2", "3"));
dest = {"4", "5"};
EXPECT_EQ(dest, Seq("4", "5"));
dest = source;
EXPECT_EQ(dest, Seq("1", "2", "3"));
EXPECT_EQ(source, Seq("1", "2", "3"));
}
}

TEST(inplace_vector, TransfersOfOwnership)
{
{
Expand Down

0 comments on commit 2ee020a

Please sign in to comment.