mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Added return reference from stack::emplace
This commit is contained in:
parent
00b6c9fcb4
commit
99b2dacb6c
@ -283,13 +283,15 @@ namespace etl
|
||||
///\param value The value to push to the stack.
|
||||
//*************************************************************************
|
||||
template <typename ... Args>
|
||||
void emplace(Args && ... args)
|
||||
reference emplace(Args && ... args)
|
||||
{
|
||||
#if defined(ETL_CHECK_PUSH_POP)
|
||||
ETL_ASSERT(!full(), ETL_ERROR(stack_full));
|
||||
#endif
|
||||
base_t::add_in();
|
||||
::new (&p_buffer[top_index]) T(etl::forward<Args>(args)...);
|
||||
|
||||
return p_buffer[top_index];
|
||||
}
|
||||
#else
|
||||
//*************************************************************************
|
||||
@ -297,13 +299,15 @@ namespace etl
|
||||
/// If asserts or exceptions are enabled, throws an etl::stack_full if the stack is already full.
|
||||
///\param value The value to push to the stack.
|
||||
//*************************************************************************
|
||||
void emplace()
|
||||
reference emplace()
|
||||
{
|
||||
#if defined(ETL_CHECK_PUSH_POP)
|
||||
ETL_ASSERT(!full(), ETL_ERROR(stack_full));
|
||||
#endif
|
||||
base_t::add_in();
|
||||
::new (&p_buffer[top_index]) T();
|
||||
|
||||
return p_buffer[top_index];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -312,13 +316,15 @@ namespace etl
|
||||
///\param value The value to push to the stack.
|
||||
//*************************************************************************
|
||||
template <typename T1>
|
||||
void emplace(const T1& value1)
|
||||
reference emplace(const T1& value1)
|
||||
{
|
||||
#if defined(ETL_CHECK_PUSH_POP)
|
||||
ETL_ASSERT(!full(), ETL_ERROR(stack_full));
|
||||
#endif
|
||||
base_t::add_in();
|
||||
::new (&p_buffer[top_index]) T(value1);
|
||||
|
||||
return p_buffer[top_index];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -327,13 +333,15 @@ namespace etl
|
||||
///\param value The value to push to the stack.
|
||||
//*************************************************************************
|
||||
template <typename T1, typename T2>
|
||||
void emplace(const T1& value1, const T2& value2)
|
||||
reference emplace(const T1& value1, const T2& value2)
|
||||
{
|
||||
#if defined(ETL_CHECK_PUSH_POP)
|
||||
ETL_ASSERT(!full(), ETL_ERROR(stack_full));
|
||||
#endif
|
||||
base_t::add_in();
|
||||
::new (&p_buffer[top_index]) T(value1, value2);
|
||||
|
||||
return p_buffer[top_index];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -342,13 +350,15 @@ namespace etl
|
||||
///\param value The value to push to the stack.
|
||||
//*************************************************************************
|
||||
template <typename T1, typename T2, typename T3>
|
||||
void emplace(const T1& value1, const T2& value2, const T3& value3)
|
||||
reference emplace(const T1& value1, const T2& value2, const T3& value3)
|
||||
{
|
||||
#if defined(ETL_CHECK_PUSH_POP)
|
||||
ETL_ASSERT(!full(), ETL_ERROR(stack_full));
|
||||
#endif
|
||||
base_t::add_in();
|
||||
::new (&p_buffer[top_index]) T(value1, value2, value3);
|
||||
|
||||
return p_buffer[top_index];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -357,13 +367,15 @@ namespace etl
|
||||
///\param value The value to push to the stack.
|
||||
//*************************************************************************
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
void emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
|
||||
reference emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
|
||||
{
|
||||
#if defined(ETL_CHECK_PUSH_POP)
|
||||
ETL_ASSERT(!full(), ETL_ERROR(stack_full));
|
||||
#endif
|
||||
base_t::add_in();
|
||||
::new (&p_buffer[top_index]) T(value1, value2, value3, value4);
|
||||
|
||||
return p_buffer[top_index];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -231,28 +231,38 @@ namespace
|
||||
{
|
||||
etl::stack<Item, 5> stack;
|
||||
|
||||
stack.emplace();
|
||||
Item& item1 = stack.emplace();
|
||||
CHECK_EQUAL(1U, stack.size());
|
||||
|
||||
stack.emplace('b', 2, 2.3);
|
||||
Item& item2 = stack.emplace('b', 2, 2.3);
|
||||
CHECK_EQUAL(2U, stack.size());
|
||||
|
||||
stack.emplace('c', 3, 3.4);
|
||||
Item& item3 = stack.emplace('c', 3, 3.4);
|
||||
CHECK_EQUAL(3U, stack.size());
|
||||
|
||||
stack.emplace('d', 4, 4.5);
|
||||
Item& item4 = stack.emplace('d', 4, 4.5);
|
||||
CHECK_EQUAL(4U, stack.size());
|
||||
|
||||
stack.emplace('e', 5, 5.6);
|
||||
Item& item5 = stack.emplace('e', 5, 5.6);
|
||||
CHECK_EQUAL(5U, stack.size());
|
||||
|
||||
CHECK(item1 == Item('a', 1, 1.2));
|
||||
CHECK(item2 == Item('b', 2, 2.3));
|
||||
CHECK(item3 == Item('c', 3, 3.4));
|
||||
CHECK(item4 == Item('d', 4, 4.5));
|
||||
CHECK(item5 == Item('e', 5, 5.6));
|
||||
|
||||
CHECK(stack.top() == Item('e', 5, 5.6));
|
||||
|
||||
stack.pop();
|
||||
CHECK(stack.top() == Item('d', 4, 4.5));
|
||||
|
||||
stack.pop();
|
||||
CHECK(stack.top() == Item('c', 3, 3.4));
|
||||
|
||||
stack.pop();
|
||||
CHECK(stack.top() == Item('b', 2, 2.3));
|
||||
|
||||
stack.pop();
|
||||
CHECK(stack.top() == Item('a', 1, 1.2));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user