mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 14:49:53 +08:00
Added 'pop_into' member functions.
This commit is contained in:
parent
29c9b658d7
commit
b885ad3d33
@ -269,6 +269,16 @@ namespace etl
|
||||
container.pop_back();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the highest priority value in the priority queue
|
||||
/// and assigns it to destination and removes it from the queue.
|
||||
//*************************************************************************
|
||||
void pop_into(reference destination)
|
||||
{
|
||||
destination = top();
|
||||
pop();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the current number of items in the priority queue.
|
||||
//*************************************************************************
|
||||
|
||||
11
src/queue.h
11
src/queue.h
@ -361,6 +361,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Removes the oldest value from the back of the queue.
|
||||
/// Does nothing if the queue is already empty.
|
||||
/// If asserts or exceptions are enabled, throws an etl::queue_empty if the queue is empty.
|
||||
//*************************************************************************
|
||||
void pop()
|
||||
{
|
||||
@ -373,6 +374,16 @@ namespace etl
|
||||
--construct_count;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets the oldest value and removes it from the front of the queue.
|
||||
/// If asserts or exceptions are enabled, throws an etl::queue_empty if the queue is empty.
|
||||
//*************************************************************************
|
||||
void pop_into(reference destination)
|
||||
{
|
||||
destination = front();
|
||||
pop();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
|
||||
10
src/stack.h
10
src/stack.h
@ -330,7 +330,6 @@ namespace etl
|
||||
|
||||
//*************************************************************************
|
||||
/// Removes the oldest item from the top of the stack.
|
||||
/// Does nothing if the stack is already empty.
|
||||
//*************************************************************************
|
||||
void pop()
|
||||
{
|
||||
@ -343,6 +342,15 @@ namespace etl
|
||||
--construct_count;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Removes the oldest item from the top of the stack and puts it in the destination.
|
||||
//*************************************************************************
|
||||
void pop_into(reference destination)
|
||||
{
|
||||
destination = top();
|
||||
pop();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
|
||||
@ -99,6 +99,7 @@
|
||||
<Unit filename="../../src/etl_arduino.h" />
|
||||
<Unit filename="../../src/exception.h" />
|
||||
<Unit filename="../../src/factorial.h" />
|
||||
<Unit filename="../../src/factory.h" />
|
||||
<Unit filename="../../src/fibonacci.h" />
|
||||
<Unit filename="../../src/fixed_iterator.h" />
|
||||
<Unit filename="../../src/flat_map.h" />
|
||||
@ -283,6 +284,7 @@
|
||||
<Unit filename="../test_enum_type.cpp" />
|
||||
<Unit filename="../test_error_handler.cpp" />
|
||||
<Unit filename="../test_exception.cpp" />
|
||||
<Unit filename="../test_factory.cpp" />
|
||||
<Unit filename="../test_fixed_iterator.cpp" />
|
||||
<Unit filename="../test_flat_map.cpp" />
|
||||
<Unit filename="../test_flat_multimap.cpp" />
|
||||
@ -318,6 +320,7 @@
|
||||
<Unit filename="../test_observer.cpp" />
|
||||
<Unit filename="../test_optional.cpp" />
|
||||
<Unit filename="../test_packet.cpp" />
|
||||
<Unit filename="../test_parameter_type.cpp" />
|
||||
<Unit filename="../test_pearson.cpp" />
|
||||
<Unit filename="../test_pool.cpp" />
|
||||
<Unit filename="../test_priority_queue.cpp" />
|
||||
|
||||
@ -377,6 +377,31 @@ namespace
|
||||
CHECK_EQUAL(compare_priority_queue.size(), priority_queue.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pop_into)
|
||||
{
|
||||
etl::priority_queue<int, SIZE> priority_queue;
|
||||
|
||||
priority_queue.push(1);
|
||||
priority_queue.push(3);
|
||||
priority_queue.push(4);
|
||||
priority_queue.push(2);
|
||||
|
||||
int i;
|
||||
|
||||
priority_queue.pop_into(i);
|
||||
CHECK_EQUAL(4, i);
|
||||
|
||||
priority_queue.pop_into(i);
|
||||
CHECK_EQUAL(3, i);
|
||||
|
||||
priority_queue.pop_into(i);
|
||||
CHECK_EQUAL(2, i);
|
||||
|
||||
priority_queue.pop_into(i);
|
||||
CHECK_EQUAL(1, i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_assignment)
|
||||
{
|
||||
|
||||
@ -339,6 +339,31 @@ namespace
|
||||
CHECK_EQUAL(1U, queue.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pop_into)
|
||||
{
|
||||
etl::queue<int, 4> queue;
|
||||
|
||||
int i;
|
||||
|
||||
queue.push(1);
|
||||
queue.push(2);
|
||||
queue.push(3);
|
||||
queue.push(4);
|
||||
|
||||
queue.pop_into(i);
|
||||
CHECK_EQUAL(1, i);
|
||||
|
||||
queue.pop_into(i);
|
||||
CHECK_EQUAL(2, i);
|
||||
|
||||
queue.pop_into(i);
|
||||
CHECK_EQUAL(3, i);
|
||||
|
||||
queue.pop_into(i);
|
||||
CHECK_EQUAL(4, i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pop_exception)
|
||||
{
|
||||
|
||||
@ -223,6 +223,31 @@ namespace
|
||||
CHECK_EQUAL(1U, stack.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pop_into)
|
||||
{
|
||||
etl::stack<int, 4> stack;
|
||||
|
||||
int i;
|
||||
|
||||
stack.push(1);
|
||||
stack.push(2);
|
||||
stack.push(3);
|
||||
stack.push(4);
|
||||
|
||||
stack.pop_into(i);
|
||||
CHECK_EQUAL(4U, i);
|
||||
|
||||
stack.pop_into(i);
|
||||
CHECK_EQUAL(3U, i);
|
||||
|
||||
stack.pop_into(i);
|
||||
CHECK_EQUAL(2U, i);
|
||||
|
||||
stack.pop_into(i);
|
||||
CHECK_EQUAL(1U, i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pop_excess)
|
||||
{
|
||||
|
||||
@ -92,7 +92,7 @@
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_IN_UNIT_TEST;ETL_THROW_EXCEPTIONS;ETL_VERBOSE_ERRORS;ETL_CHECK_PUSH_POP;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_IVECTOR_REPAIR_ENABLE;ETL_ISTRING_REPAIR_ENABLE;ETL_IDEQUE_REPAIR_ENABLE;ETL_IN_UNIT_TEST;ETL_THROW_EXCEPTIONS;ETL_VERBOSE_ERRORS;ETL_CHECK_PUSH_POP;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>../../unittest-cpp/UnitTest++/;../../src</AdditionalIncludeDirectories>
|
||||
<UndefinePreprocessorDefinitions>
|
||||
</UndefinePreprocessorDefinitions>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user