deque check index operator

This commit is contained in:
Mike Bloom 2026-10-04 15:38:14 +00:00
parent 27ce9364ec
commit f61ea66d84
2 changed files with 38 additions and 1 deletions

View File

@ -791,6 +791,8 @@ namespace etl
//*************************************************************************
reference operator[](size_t index)
{
ETL_ASSERT_CHECK_INDEX_OPERATOR(index < current_size, ETL_ERROR(deque_out_of_bounds));
iterator result(_begin);
result += static_cast<difference_type>(index);
@ -803,6 +805,8 @@ namespace etl
//*************************************************************************
const_reference operator[](size_t index) const
{
ETL_ASSERT_CHECK_INDEX_OPERATOR(index < current_size, ETL_ERROR(deque_out_of_bounds));
iterator result(_begin);
result += static_cast<difference_type>(index);
@ -2196,7 +2200,8 @@ namespace etl
iterator item = _begin;
do {
do
{
::new (&(*item)) T(*from);
++item;
++from;

View File

@ -394,6 +394,14 @@ namespace
CHECK_EQUAL(compare_data.at(5), data.at(5));
}
//*************************************************************************
TEST(test_at_out_of_bounds)
{
DataNDC data(initial_data.begin(), initial_data.end());
CHECK_THROW(data.at(data.size()), etl::deque_out_of_bounds);
}
//*************************************************************************
TEST(test_at_const)
{
@ -408,6 +416,14 @@ namespace
CHECK_EQUAL(compare_data.at(5), data.at(5));
}
//*************************************************************************
TEST(test_at_const_out_of_bounds)
{
const DataNDC data(initial_data.begin(), initial_data.end());
CHECK_THROW(data.at(data.size()), etl::deque_out_of_bounds);
}
//*************************************************************************
TEST(test_index_operator)
{
@ -422,6 +438,14 @@ namespace
CHECK_EQUAL(compare_data[5], data[5]);
}
//*************************************************************************
TEST(test_index_operator_out_of_bounds)
{
DataNDC data(initial_data.begin(), initial_data.end());
CHECK_THROW(data[data.size()], etl::deque_out_of_bounds);
}
//*************************************************************************
TEST(test_index_operator_const)
{
@ -436,6 +460,14 @@ namespace
CHECK_EQUAL(compare_data[5], data[5]);
}
//*************************************************************************
TEST(test_index_operator_const_out_of_bounds)
{
const DataNDC data(initial_data.begin(), initial_data.end());
CHECK_THROW(data[data.size()], etl::deque_out_of_bounds);
}
//*************************************************************************
TEST(test_front)
{