#include <gtest/gtest.h>
template <typename T>
void add_hello_world(T& container)
{
container.reserve(12);
container.push_back('H');
container.push_back('e');
container.push_back('l');
container.push_back('l');
container.push_back('o');
container.push_back(' ');
container.push_back('W');
container.push_back('o');
container.push_back('r');
container.push_back('l');
container.push_back('d');
}
template <typename T>
void print_container(const T& container)
{
for (auto c : container)
{
}
}
#ifdefined(__cpp_exceptions)
TEST(example_08_variable_length_array_vs_vector, example_tight_fit_0)
{
array_storage_1.max_size()};
try
{
{
space_waster.push_back(static_cast<char>(i + 46));
}
{
std::cout <<
"<- vector claimed to have run out of memory but we know better." <<
std::endl;
}
}
TEST(example_08_variable_length_array_vs_vector, example_tight_fit_1)
{
array_storage_1.max_size()};
array_storage_0.size(),
{&array_storage_0},
};
{
tight_fit.push_back(static_cast<char>(i + 46));
}
std::cout <<
"<- The VLA was able to fit tightly inside of the maximum size it was given." <<
std::endl;
}
TEST(example_08_variable_length_array_vs_vector, example_exact_fit)
{
array_storage_0.size(),
{&array_storage_0},
};
{
exact_fit.push_back(static_cast<char>(i + 46));
}
}
TEST(example_08_variable_length_array_vs_vector, example_no_exceptions)
{
}
#else
TEST(example_08_variable_length_array_vs_vector, example_no_exceptions)
{
add_hello_world(a);
add_hello_world(b);
print_container(a);
print_container(b);
bad_b.push_back('H');
if (bad_b.size() == size_before)
{
if (size_before == bad_b.max_size())
{
std::cout <<
"bad_b was not able to allocate memory because it reached its max_size. You probably should "
"have checked this first? Just sayin'."
}
else
{
}
}
}
#endif
Defines a memory_resource type backed by an array data member and using cetl::pf17 types.
Minimal, generic container for storing Cyphal variable-length arrays.
Definition variable_length_array.hpp:893
void reserve(const size_type desired_capacity)
Ensure enough memory is allocated to store at least the desired_capacity number of elements.
Definition variable_length_array.hpp:1359
constexpr void push_back(const value_type &value)
Allocate a new element on to the back of the array and copy value into it.
Definition variable_length_array.hpp:1414
Implementation of cetl::pf17::pmr::memory_resource that uses cetl::pmr::UnsynchronizedBufferMemoryRes...
Definition array_memory_resource.hpp:45
Adheres to the std::pmr::polymorphic_allocator specification.
Definition memory_resource.hpp:356
memory_resource * null_memory_resource() noexcept
Adheres to the null_memory_resource specification.
Definition memory_resource.hpp:303
Extends the cetl::pf17::pmr namespace with system memory resources.
Includes cetl::VariableLengthArray type and non-member functions.