diff --git a/src/priority_queue.h b/src/priority_queue.h
index cda9b7b4..08ace478 100644
--- a/src/priority_queue.h
+++ b/src/priority_queue.h
@@ -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.
//*************************************************************************
diff --git a/src/queue.h b/src/queue.h
index 67b77272..4580a299 100644
--- a/src/queue.h
+++ b/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.
//*************************************************************************
diff --git a/src/stack.h b/src/stack.h
index 0740c58d..b5aabf82 100644
--- a/src/stack.h
+++ b/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.
//*************************************************************************
diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp
index ec3baea7..415929e1 100644
--- a/test/codeblocks/ETL.cbp
+++ b/test/codeblocks/ETL.cbp
@@ -99,6 +99,7 @@
+
@@ -283,6 +284,7 @@
+
@@ -318,6 +320,7 @@
+
diff --git a/test/test_priority_queue.cpp b/test/test_priority_queue.cpp
index b35468c3..8db4ca9c 100644
--- a/test/test_priority_queue.cpp
+++ b/test/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 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)
{
diff --git a/test/test_queue.cpp b/test/test_queue.cpp
index 4a62b3fb..c9724135 100644
--- a/test/test_queue.cpp
+++ b/test/test_queue.cpp
@@ -339,6 +339,31 @@ namespace
CHECK_EQUAL(1U, queue.size());
}
+ //*************************************************************************
+ TEST(test_pop_into)
+ {
+ etl::queue 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)
{
diff --git a/test/test_stack.cpp b/test/test_stack.cpp
index 448e691f..35d287a1 100644
--- a/test/test_stack.cpp
+++ b/test/test_stack.cpp
@@ -223,6 +223,31 @@ namespace
CHECK_EQUAL(1U, stack.size());
}
+ //*************************************************************************
+ TEST(test_pop_into)
+ {
+ etl::stack 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)
{
diff --git a/test/vs2017/etl.vcxproj b/test/vs2017/etl.vcxproj
index 0fa4cfb3..d9b6d6a7 100644
--- a/test/vs2017/etl.vcxproj
+++ b/test/vs2017/etl.vcxproj
@@ -92,7 +92,7 @@
Level3
Disabled
- 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)
+ 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)
../../unittest-cpp/UnitTest++/;../../src