flat_buffer improvements:

fix #1345

* Revise documentation
* Add reserve() member
* Add max_size() member
* Respect Allocator max_size
* Specify exception safety
This commit is contained in:
Vinnie Falco
2018-12-07 13:00:51 -08:00
parent 5a42490921
commit 11c71d118f
4 changed files with 339 additions and 154 deletions
+23 -1
View File
@@ -292,8 +292,10 @@ public:
BEAST_EXPECT(buffers_to_string(b2.data()) == s.substr(7));
}
{
flat_buffer b2{64};
flat_buffer b2{32};
BEAST_EXPECT(b2.max_size() == 32);
b2 = b1;
BEAST_EXPECT(b2.max_size() == b1.max_size());
BEAST_EXPECT(buffers_to_string(b2.data()) == s);
b2.consume(7);
BEAST_EXPECT(buffers_to_string(b2.data()) == s.substr(7));
@@ -309,6 +311,14 @@ public:
BEAST_EXPECT(buffers_to_string(b.data()) == "4567890123");
}
// max_size
{
flat_buffer b{10};
BEAST_EXPECT(b.max_size() == 10);
b.max_size(32);
BEAST_EXPECT(b.max_size() == 32);
}
// read_size
{
flat_buffer b{10};
@@ -372,6 +382,18 @@ public:
}
}
// reserve
{
flat_buffer b;
BEAST_EXPECT(b.capacity() == 0);
b.reserve(50);
BEAST_EXPECT(b.capacity() == 50);
b.prepare(20);
b.commit(20);
b.reserve(50);
BEAST_EXPECT(b.capacity() == 50);
}
// shrink to fit
{
flat_buffer b;