вт, 21 мая 2024 г. в 08:03, Ion Gaztañaga via Boost :
<...>
Note that this document does not outline a schedule for all those ideas,
it's an initial description of possible developments that should be
evaluated/prioritized, as developing a substantial subset of the
proposals would be a huge task.
Thanks in advance for your attention and comments.
There's one container that I find really useful and that is not in a
list. It's a dynamically allocated array that knows its size and
allows initialization of elements with the initial value or via a
lambda.
If fills the gap between vector and unique_ptr:
* works with non-movable and non-copyable types (unlike vector)
* works with not default constructible types (unlike unique_ptr)
* has continuous layout
* usable with range based for (unlike unique_ptr)
* smaller than vector (does not need to store capacity)
Here's a prototype
https://github.com/userver-framework/userver/blob/develop/universal/include/...
We called that container FixedArray, because it is an array of a fixed
size. And because it "fixes" the issues of dynamically allocated
arrays.
Usage examples:
auto clients = utils::GenerateFixedArray(clients_count, [](int index) {
return NonMovableClient(connection_string_to_client_with_index(index));
});
ASSERT_EQ(clients.size(), clients_count);
// ...
for (auto& client: clients) {
client.SendRequest(x);
}
Another example:
FixedArray atomics(count, initial_value_for_each_atomic);
--
Best regards,
Antony Polukhin