Added c++03 zero parameter emplace member functions

This commit is contained in:
John Wellbelove 2023-08-25 02:05:46 +01:00
parent 7e266687a2
commit 53084ae932
47 changed files with 1564 additions and 181 deletions

2
.gitignore vendored
View File

@ -384,3 +384,5 @@ test/vs2022/Debug MSVC C++ 20 - No Tests
test/vs2022/enc_temp_folder
test/vs2022/Debug MSVC C++20 - No virtual messages
examples/MutexMessageRouter/.vs
support/time remaining test.xlsx
test/vs2022/Debug MSVC C++20 - Force C++03

View File

@ -248,14 +248,7 @@ namespace etl
template <typename TIterator1, typename TIterator2>
ETL_CONSTEXPR14 TIterator2 move(TIterator1 sb, TIterator1 se, TIterator2 db)
{
while (sb != se)
{
*db = *sb;
++db;
++sb;
}
return db;
return copy(sb, se, db);
}
#endif
@ -284,12 +277,7 @@ namespace etl
template <typename TIterator1, typename TIterator2>
ETL_CONSTEXPR14 TIterator2 move_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
{
while (sb != se)
{
*(--de) = *(--se);
}
return de;
return etl::copy_backward(sb, se, de);
}
#endif

View File

@ -1757,6 +1757,23 @@ namespace etl
#else
//*************************************************************************
/// Emplaces an item to the back of the deque.
/// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full.
//*************************************************************************
reference emplace_back()
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(!full(), ETL_ERROR(deque_full));
#endif
::new (&(*_end)) T();
++_end;
++current_size;
ETL_INCREMENT_DEBUG_COUNT
return back();
}
//*************************************************************************
/// Emplaces an item to the back of the deque.
/// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full.
@ -1890,6 +1907,23 @@ namespace etl
#else
//*************************************************************************
/// Emplaces an item to the front of the deque.
/// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full.
//*************************************************************************
reference emplace_front()
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(!full(), ETL_ERROR(deque_full));
#endif
--_begin;
::new (&(*_begin)) T();
++current_size;
ETL_INCREMENT_DEBUG_COUNT
return front();
}
//*************************************************************************
/// Emplaces an item to the front of the deque.
/// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full.

View File

@ -319,7 +319,7 @@ namespace etl
//*************************************************************************
/// Emplaces a value to the set.
//*************************************************************************
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_FLAT_MULTISET_FORCE_CPP03_IMPLEMENTATION)
template <typename ... Args>
ETL_OR_STD::pair<iterator, bool> emplace(Args && ... args)
{
@ -332,9 +332,26 @@ namespace etl
iterator i_element = upper_bound(*pvalue);
ETL_INCREMENT_DEBUG_COUNT
return ETL_OR_STD::pair<iterator, bool>(refset_t::insert_at(i_element, *pvalue));
return ETL_OR_STD::pair<iterator, bool>(refset_t::insert_at(i_element, *pvalue));
}
#else
//*************************************************************************
/// Emplaces a value to the set.
//*************************************************************************
ETL_OR_STD::pair<iterator, bool> emplace()
{
ETL_ASSERT(!full(), ETL_ERROR(flat_multiset_full));
// Create it.
value_type* pvalue = storage.allocate<value_type>();
::new (pvalue) value_type();
iterator i_element = upper_bound(*pvalue);
ETL_INCREMENT_DEBUG_COUNT
return ETL_OR_STD::pair<iterator, bool>(refset_t::insert_at(i_element, *pvalue));
}
//*************************************************************************
/// Emplaces a value to the set.
//*************************************************************************
@ -350,7 +367,7 @@ namespace etl
iterator i_element = upper_bound(*pvalue);
ETL_INCREMENT_DEBUG_COUNT
return ETL_OR_STD::pair<iterator, bool>(refset_t::insert_at(i_element, *pvalue));
return ETL_OR_STD::pair<iterator, bool>(refset_t::insert_at(i_element, *pvalue));
}
//*************************************************************************
@ -368,7 +385,7 @@ namespace etl
iterator i_element = upper_bound(*pvalue);
ETL_INCREMENT_DEBUG_COUNT
return ETL_OR_STD::pair<iterator, bool>(refset_t::insert_at(i_element, *pvalue));
return ETL_OR_STD::pair<iterator, bool>(refset_t::insert_at(i_element, *pvalue));
}
//*************************************************************************
@ -386,7 +403,7 @@ namespace etl
iterator i_element = upper_bound(*pvalue);
ETL_INCREMENT_DEBUG_COUNT
return ETL_OR_STD::pair<iterator, bool>(refset_t::insert_at(i_element, *pvalue));
return ETL_OR_STD::pair<iterator, bool>(refset_t::insert_at(i_element, *pvalue));
}
//*************************************************************************
@ -404,7 +421,7 @@ namespace etl
iterator i_element = upper_bound(*pvalue);
ETL_INCREMENT_DEBUG_COUNT
return ETL_OR_STD::pair<iterator, bool>(refset_t::insert_at(i_element, *pvalue));
return ETL_OR_STD::pair<iterator, bool>(refset_t::insert_at(i_element, *pvalue));
}
#endif

View File

@ -326,7 +326,7 @@ namespace etl
//*************************************************************************
/// Emplaces a value to the set.
//*************************************************************************
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_FLAT_SET_FORCE_CPP03_IMPLEMENTATION)
template <typename ... Args>
ETL_OR_STD::pair<iterator, bool> emplace(Args && ... args)
{
@ -357,6 +357,38 @@ namespace etl
return result;
}
#else
//*************************************************************************
/// Emplaces a value to the set.
//*************************************************************************
ETL_OR_STD::pair<iterator, bool> emplace()
{
ETL_ASSERT(!full(), ETL_ERROR(flat_set_full));
ETL_OR_STD::pair<iterator, bool> result;
// Create it.
value_type* pvalue = storage.allocate<value_type>();
::new (pvalue) value_type();
iterator i_element = lower_bound(*pvalue);
// Doesn't already exist?
if ((i_element == end()) || compare(*pvalue, *i_element))
{
ETL_INCREMENT_DEBUG_COUNT
result = refset_t::insert_at(i_element, *pvalue);
}
else
{
// Destroy it.
pvalue->~value_type();
storage.release(pvalue);
result = ETL_OR_STD::pair<iterator, bool>(end(), false);
}
return result;
}
//*************************************************************************
/// Emplaces a value to the set.
//*************************************************************************

View File

@ -717,7 +717,7 @@ namespace etl
}
#endif
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_FORWARD_LIST_FORCE_CPP03_IMPLEMENTATION)
//*************************************************************************
/// Emplaces a value to the front of the list..
//*************************************************************************
@ -734,6 +734,21 @@ namespace etl
return front();
}
#else
//*************************************************************************
/// Emplaces a value to the front of the list..
//*************************************************************************
reference emplace_front()
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
#endif
data_node_t* p_data_node = allocate_data_node();
::new (&(p_data_node->value)) T();
ETL_INCREMENT_DEBUG_COUNT
insert_node_after(start_node, *p_data_node);
return front();
}
//*************************************************************************
/// Emplaces a value to the front of the list..
//*************************************************************************
@ -879,7 +894,7 @@ namespace etl
return iterator(&data_node);
}
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_FORWARD_LIST_FORCE_CPP03_IMPLEMENTATION)
//*************************************************************************
/// Emplaces a value to the forward_list after the specified position.
//*************************************************************************
@ -896,6 +911,21 @@ namespace etl
return iterator(p_data_node);
}
#else
//*************************************************************************
/// Emplaces a value to the forward_list after the specified position.
//*************************************************************************
iterator emplace_after(const_iterator position)
{
ETL_ASSERT(!full(), ETL_ERROR(forward_list_full));
data_node_t* p_data_node = allocate_data_node();
::new (&(p_data_node->value)) T();
ETL_INCREMENT_DEBUG_COUNT
insert_node_after(*to_iterator(position).p_node, *p_data_node);
return iterator(p_data_node);
}
//*************************************************************************
/// Emplaces a value to the forward_list after the specified position.
//*************************************************************************
@ -907,7 +937,7 @@ namespace etl
data_node_t* p_data_node = allocate_data_node();
::new (&(p_data_node->value)) T(value1);
ETL_INCREMENT_DEBUG_COUNT
insert_node_after(*position.p_node, *p_data_node);
insert_node_after(*to_iterator(position).p_node, *p_data_node);
return iterator(p_data_node);
}
@ -923,7 +953,7 @@ namespace etl
data_node_t* p_data_node = allocate_data_node();
::new (&(p_data_node->value)) T(value1, value2);
ETL_INCREMENT_DEBUG_COUNT
insert_node_after(*position.p_node, *p_data_node);
insert_node_after(*to_iterator(position).p_node, *p_data_node);
return iterator(p_data_node);
}
@ -939,7 +969,7 @@ namespace etl
data_node_t* p_data_node = allocate_data_node();
::new (&(p_data_node->value)) T(value1, value2, value3);
ETL_INCREMENT_DEBUG_COUNT
insert_node_after(*position.p_node, *p_data_node);
insert_node_after(*to_iterator(position).p_node, *p_data_node);
return iterator(p_data_node);
}
@ -955,7 +985,7 @@ namespace etl
data_node_t* p_data_node = allocate_data_node();
::new (&(p_data_node->value)) T(value1, value2, value3, value4);
ETL_INCREMENT_DEBUG_COUNT
insert_node_after(*position.p_node, *p_data_node);
insert_node_after(*to_iterator(position).p_node, *p_data_node);
return iterator(p_data_node);
}

View File

@ -789,6 +789,18 @@ namespace etl
return back();
}
#else
//*********************************************************************
/// Constructs a value at the end of the indirect_vector.
/// If asserts or exceptions are enabled, emits vector_full if the indirect_vector is already full.
///\param value The value to add.
//*********************************************************************
reference emplace_back()
{
T* p = storage.create<T>(T());
lookup.push_back(p);
return back();
}
//*********************************************************************
/// Constructs a value at the end of the indirect_vector.
/// If asserts or exceptions are enabled, emits vector_full if the indirect_vector is already full.
@ -891,7 +903,7 @@ namespace etl
//*************************************************************************
/// Emplaces a value to the vector at the specified position.
//*************************************************************************
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_VECTOR_FORCE_CPP03_IMPLEMENTATION)
template <typename ... Args>
iterator emplace(iterator position, Args && ... args)
{
@ -903,6 +915,16 @@ namespace etl
return position;
}
#else
iterator emplace(iterator position)
{
ETL_ASSERT(!full(), ETL_ERROR(vector_full));
T* p = storage.create<T>(T());
position = iterator(lookup.insert(position.lookup_itr, p));
return position;
}
template <typename T1>
iterator emplace(iterator position, const T1& value1)
{

View File

@ -857,7 +857,7 @@ namespace etl
}
#endif
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_LIST_FORCE_CPP03_IMPLEMENTATION)
//*************************************************************************
/// Emplaces a value to the front of the list.
//*************************************************************************
@ -876,6 +876,23 @@ namespace etl
return front();
}
#else
//*************************************************************************
/// Emplaces a value to the front of the list.
//*************************************************************************
reference emplace_front()
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(!full(), ETL_ERROR(list_full));
#endif
ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool));
data_node_t* p_data_node = allocate_data_node();
::new (&(p_data_node->value)) T();
ETL_INCREMENT_DEBUG_COUNT
insert_node(get_head(), *p_data_node);
return front();
}
//*************************************************************************
/// Emplaces a value to the front of the list.
//*************************************************************************
@ -1004,6 +1021,20 @@ namespace etl
return back();
}
#else
reference emplace_back()
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(!full(), ETL_ERROR(list_full));
#endif
ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool));
data_node_t* p_data_node = allocate_data_node();
::new (&(p_data_node->value)) T();
ETL_INCREMENT_DEBUG_COUNT
insert_node(terminal_node, *p_data_node);
return back();
}
template <typename T1>
reference emplace_back(const T1& value1)
{
@ -1108,9 +1139,9 @@ namespace etl
//*************************************************************************
/// Emplaces a value to the list at the specified position.
//*************************************************************************
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_LIST_FORCE_CPP03_IMPLEMENTATION)
template <typename ... Args>
iterator emplace(const_iterator position, Args && ... args)
iterator emplace(const_iterator position, Args&& ... args)
{
ETL_ASSERT(!full(), ETL_ERROR(list_full));
ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool));
@ -1123,6 +1154,19 @@ namespace etl
return iterator(*p_data_node);
}
#else
iterator emplace(const_iterator position)
{
ETL_ASSERT(!full(), ETL_ERROR(list_full));
ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool));
data_node_t* p_data_node = allocate_data_node();
::new (&(p_data_node->value)) T();
ETL_INCREMENT_DEBUG_COUNT
insert_node(*to_iterator(position).p_node, *p_data_node);
return iterator(*p_data_node);
}
template <typename T1>
iterator emplace(const_iterator position, const T1& value1)
{
@ -1132,7 +1176,8 @@ namespace etl
data_node_t* p_data_node = allocate_data_node();
::new (&(p_data_node->value)) T(value1);
ETL_INCREMENT_DEBUG_COUNT
insert_node(*position.p_node, *p_data_node);
iterator(*p_data_node).p_node;
insert_node(*to_iterator(position).p_node, *p_data_node);
return iterator(*p_data_node);
}
@ -1146,7 +1191,7 @@ namespace etl
data_node_t* p_data_node = allocate_data_node();
::new (&(p_data_node->value)) T(value1, value2);
ETL_INCREMENT_DEBUG_COUNT
insert_node(*position.p_node, *p_data_node);
insert_node(*to_iterator(position).p_node, *p_data_node);
return iterator(*p_data_node);
}
@ -1160,7 +1205,7 @@ namespace etl
data_node_t* p_data_node = allocate_data_node();
::new (&(p_data_node->value)) T(value1, value2, value3);
ETL_INCREMENT_DEBUG_COUNT
insert_node(*position.p_node, *p_data_node);
insert_node(*to_iterator(position).p_node, *p_data_node);
return iterator(*p_data_node);
}
@ -1174,7 +1219,7 @@ namespace etl
data_node_t* p_data_node = allocate_data_node();
::new (&(p_data_node->value)) T(value1, value2, value3, value4);
ETL_INCREMENT_DEBUG_COUNT
insert_node(*position.p_node, *p_data_node);
insert_node(*to_iterator(position).p_node, *p_data_node);
return iterator(*p_data_node);
}

View File

@ -115,6 +115,8 @@ namespace etl
{
public:
typedef T value_type;
//***************************************************************************
/// Constructor.
//***************************************************************************
@ -487,6 +489,24 @@ namespace etl
storage.construct(etl::forward<TArgs>(args)...);
}
#else
//*************************************************************************
/// Emplaces a value.
/// 1 parameter.
//*************************************************************************
T& emplace()
{
if (has_value())
{
// Destroy the old one.
storage.destroy();
}
T* p = ::new (&storage.u.value) T();
storage.valid = true;
return *p;
}
//*************************************************************************
/// Emplaces a value.
/// 1 parameter.
@ -670,6 +690,8 @@ namespace etl
{
public:
typedef T value_type;
//***************************************************************************
/// Constructor.
//***************************************************************************
@ -1006,6 +1028,16 @@ namespace etl
valid = true;
}
#else
//*************************************************************************
/// Emplaces a value.
/// 0 parameters.
//*************************************************************************
void emplace()
{
storage.u.value = value_type();
valid = true;
}
//*************************************************************************
/// Emplaces a value.
/// 1 parameter.

View File

@ -197,6 +197,22 @@ namespace etl
etl::push_heap(container.begin(), container.end(), compare);
}
#else
//*************************************************************************
/// Emplaces a value to the queue.
/// If asserts or exceptions are enabled, throws an etl::priority_queue_full
/// is the priority queue is already full.
///\param value The value to push to the queue.
//*************************************************************************
void emplace()
{
ETL_ASSERT(!full(), ETL_ERROR(etl::priority_queue_full));
// Put element at end
container.emplace_back();
// Make elements in container into heap
etl::push_heap(container.begin(), container.end(), compare);
}
//*************************************************************************
/// Emplaces a value to the queue.
/// If asserts or exceptions are enabled, throws an etl::priority_queue_full

View File

@ -349,6 +349,18 @@ namespace etl
base_t::push_back(value);
}
//*********************************************************************
/// Constructs a value at the end of the vector.
/// If asserts or exceptions are enabled, emits vector_full if the vector is already full.
///\param value The value to add.
//*********************************************************************
reference emplace_back()
{
base_t::emplace_back(ETL_NULLPTR);
return back();
}
//*********************************************************************
/// Constructs a value at the end of the vector.
/// If asserts or exceptions are enabled, emits vector_full if the vector is already full.
@ -381,6 +393,14 @@ namespace etl
return iterator(base_t::insert(base_t::iterator(position), value));
}
//*************************************************************************
/// Emplaces a value to the vector at the specified position.
//*************************************************************************
iterator emplace(const_iterator position)
{
return iterator(base_t::emplace(base_t::iterator(position), ETL_NULLPTR));
}
//*************************************************************************
/// Emplaces a value to the vector at the specified position.
//*************************************************************************

View File

@ -462,6 +462,29 @@ namespace etl
return position_;
}
//*************************************************************************
/// Emplaces a value to the vector at the specified position.
/// If asserts or exceptions are enabled, emits vector_full if the vector is already full.
//*************************************************************************
iterator emplace(const_iterator position)
{
ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full));
iterator position_ = to_iterator(position);
if (position_ != end())
{
++p_end;
etl::copy_backward(position_, end() - 1, end());
*position_ = ETL_NULLPTR;
}
else
{
*p_end++ = ETL_NULLPTR;
}
return position_;
}
//*************************************************************************
/// Emplaces a value to the vector at the specified position.

View File

@ -520,6 +520,21 @@ namespace etl
return *static_cast<T*>(data);
}
#else
//***************************************************************************
/// Emplace with one constructor parameter.
//***************************************************************************
template <typename T>
T& emplace()
{
ETL_STATIC_ASSERT(Type_Is_Supported<T>::value, "Unsupported type");
destruct_current();
::new (static_cast<T*>(data)) T();
type_id = Type_Id_Lookup<T>::type_id;
return *static_cast<T*>(data);
}
//***************************************************************************
/// Emplace with one constructor parameter.
//***************************************************************************

View File

@ -349,6 +349,20 @@ namespace etl
add_in();
}
#else
//*************************************************************************
/// Constructs a value in the queue 'in place'.
/// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full.
///\param value The value to use to construct the item to push to the queue.
//*************************************************************************
void emplace()
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(!full(), ETL_ERROR(queue_full));
#endif
::new (&p_buffer[in]) T();
add_in();
}
//*************************************************************************
/// Constructs a value in the queue 'in place'.
/// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full.

View File

@ -369,6 +369,20 @@ namespace etl
return emplace_implementation(value1, value2, value3, value4);
}
//*************************************************************************
/// Constructs a value in the queue 'in place'.
//*************************************************************************
bool emplace()
{
this->lock();
bool result = emplace_implementation();
this->unlock();
return result;
}
//*************************************************************************
/// Constructs a value in the queue 'in place'.
//*************************************************************************

View File

@ -199,6 +199,21 @@ namespace etl
return result;
}
#else
//*************************************************************************
/// Constructs a value in the queue 'in place'.
/// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full.
//*************************************************************************
bool emplace()
{
access.lock();
bool result = emplace_implementation();
access.unlock();
return result;
}
//*************************************************************************
/// Constructs a value in the queue 'in place'.
/// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full.
@ -470,6 +485,24 @@ namespace etl
#else
//*************************************************************************
/// Constructs a value in the queue 'in place'.
//*************************************************************************
bool emplace_implementation()
{
if (current_size != MAX_SIZE)
{
::new (&p_buffer[write_index]) T();
write_index = get_next_index(write_index, MAX_SIZE);
++current_size;
return true;
}
// Queue is full.
return false;
}
//*************************************************************************
template <typename T1>
bool emplace_implementation(const T1& value1)

View File

@ -272,6 +272,28 @@ namespace etl
return false;
}
#else
//*************************************************************************
/// Constructs a value in the queue 'in place'.
/// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full.
//*************************************************************************
bool emplace()
{
size_type write_index = write.load(etl::memory_order_relaxed);
size_type next_index = get_next_index(write_index, RESERVED);
if (next_index != read.load(etl::memory_order_acquire))
{
::new (&p_buffer[write_index]) T();
write.store(next_index, etl::memory_order_release);
return true;
}
// Queue is full.
return false;
}
//*************************************************************************
/// Constructs a value in the queue 'in place'.
/// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full.

View File

@ -262,6 +262,27 @@ namespace etl
return false;
}
#else
//*************************************************************************
/// Constructs a value in the queue 'in place'.
/// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full.
//*************************************************************************
bool emplace_implementation()
{
if (current_size != MAX_SIZE)
{
::new (&p_buffer[write_index]) T();
write_index = get_next_index(write_index, MAX_SIZE);
++current_size;
return true;
}
// Queue is full.
return false;
}
//*************************************************************************
/// Constructs a value in the queue 'in place'.
/// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full.
@ -528,6 +549,21 @@ namespace etl
return result;
}
#else
//*************************************************************************
/// Constructs a value in the queue 'in place'.
/// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full.
//*************************************************************************
bool emplace()
{
TAccess::lock();
bool result = this->emplace_implementation();
TAccess::unlock();
return result;
}
//*************************************************************************
/// Constructs a value in the queue 'in place'.
/// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full.

View File

@ -320,6 +320,21 @@ namespace etl
return emplace_implementation(value1, value2, value3, value4);
}
//*************************************************************************
/// Constructs a value in the queue 'in place'.
/// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full.
//*************************************************************************
bool emplace()
{
lock();
bool result = emplace_implementation();
unlock();
return result;
}
//*************************************************************************
/// Constructs a value in the queue 'in place'.
/// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full.
@ -640,6 +655,26 @@ namespace etl
return false;
}
#else
//*************************************************************************
/// Constructs a value in the queue 'in place'.
//*************************************************************************
bool emplace_implementation()
{
if (this->current_size != this->MAX_SIZE)
{
::new (&p_buffer[this->write_index]) T();
this->write_index = this->get_next_index(this->write_index, this->MAX_SIZE);
++this->current_size;
return true;
}
// Queue is full.
return false;
}
//*************************************************************************
/// Constructs a value in the queue 'in place'.
//*************************************************************************

View File

@ -292,6 +292,20 @@ namespace etl
::new (&p_buffer[top_index]) T(etl::forward<Args>(args)...);
}
#else
//*************************************************************************
/// Constructs a value in the stack place'.
/// 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()
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(!full(), ETL_ERROR(stack_full));
#endif
base_t::add_in();
::new (&p_buffer[top_index]) T();
}
//*************************************************************************
/// Constructs a value in the stack place'.
/// If asserts or exceptions are enabled, throws an etl::stack_full if the stack is already full.

View File

@ -470,6 +470,22 @@ namespace etl
return back();
}
#else
//*********************************************************************
/// Constructs a value at the end of the vector.
/// If asserts or exceptions are enabled, emits vector_full if the vector is already full.
///\param value The value to add.
//*********************************************************************
reference emplace_back()
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full));
#endif
::new (p_end) T();
++p_end;
ETL_INCREMENT_DEBUG_COUNT
return back();
}
//*********************************************************************
/// Constructs a value at the end of the vector.
/// If asserts or exceptions are enabled, emits vector_full if the vector is already full.

View File

@ -98,6 +98,10 @@ SOFTWARE.
#define ETL_DELEGATE_FORCE_CPP03_IMPLEMENTATION
#define ETL_SINGLETON_FORCE_CPP03_IMPLEMENTATION
#define ETL_BYTE_FORCE_CPP03_IMPLEMENTATION
#define ETL_LIST_FORCE_CPP03_IMPLEMENTATION
#define ETL_FORWARD_LIST_FORCE_CPP03_IMPLEMENTATION
#define ETL_FLAT_SET_FORCE_CPP03_IMPLEMENTATION
#define ETL_FLAT_MULTISET_FORCE_CPP03_IMPLEMENTATION
#endif
#if defined(ETL_FORCE_TEST_CPP11)

View File

@ -934,7 +934,7 @@ namespace
DataNDC data(compare_data.begin(), compare_data.end());
Compare_Data::iterator cposition = compare_data.insert(compare_data.cbegin() + 3, N14);
DataNDC::iterator position = data.insert(data.cbegin() + 3, N14);
DataNDC::iterator position = data.insert(data.cbegin() + 3, N14);
CHECK_EQUAL(compare_data.size(), std::distance(data.begin(), data.end()));
CHECK_EQUAL(compare_data.size(), data.size());
@ -960,7 +960,7 @@ namespace
DataNDC data(compare_data.begin(), compare_data.end());
Compare_Data::iterator cposition = compare_data.emplace(compare_data.begin() + 3, N14.value);
DataNDC::iterator position = data.emplace(data.begin() + 3, N14.value);
DataNDC::iterator position = data.emplace(data.begin() + 3, N14.value);
CHECK_EQUAL(compare_data.size(), std::distance(data.begin(), data.end()));
CHECK_EQUAL(compare_data.size(), data.size());
@ -979,6 +979,138 @@ namespace
CHECK_EQUAL(std::distance(compare_data.begin(), cposition), std::distance(data.begin(), position));
}
//*************************************************************************
TEST(test_emplace_default)
{
const int Initial = 1;
const int Default = 2;
struct S
{
S()
: value(Default)
{
}
S(int v)
: value(v)
{
}
bool operator ==(const S& rhs) const
{
return value == rhs.value;
}
int value;
};
// First fill with Initial values.
etl::deque<S, SIZE> data;
data.resize(SIZE, S(Initial));
data.clear();
// Then emplace Default values.
for (size_t i = 0; i < SIZE; ++i)
{
data.emplace(data.end());
}
// Compare with an array of default values.
std::array<S, SIZE> compare_data;
compare_data.fill(S());
CHECK_TRUE(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
}
//*************************************************************************
TEST(test_emplace_front_default)
{
const int Initial = 1;
const int Default = 2;
struct S
{
S()
: value(Default)
{
}
S(int v)
: value(v)
{
}
bool operator ==(const S& rhs) const
{
return value == rhs.value;
}
int value;
};
// First fill with Initial values.
etl::deque<S, SIZE> data;
data.resize(SIZE, S(Initial));
data.clear();
// Then emplace Default values.
for (size_t i = 0; i < SIZE; ++i)
{
data.emplace_front();
}
// Compare with an array of default values.
std::array<S, SIZE> compare_data;
compare_data.fill(S());
CHECK_TRUE(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
}
//*************************************************************************
TEST(test_emplace_back_default)
{
const int Initial = 1;
const int Default = 2;
struct S
{
S()
: value(Default)
{
}
S(int v)
: value(v)
{
}
bool operator ==(const S& rhs) const
{
return value == rhs.value;
}
int value;
};
// First fill with Initial values.
etl::deque<S, SIZE> data;
data.resize(SIZE, S(Initial));
data.clear();
// Then emplace Default values.
for (size_t i = 0; i < SIZE; ++i)
{
data.emplace_back();
}
// Compare with an array of default values.
std::array<S, SIZE> compare_data;
compare_data.fill(S());
CHECK_TRUE(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
}
//*************************************************************************
TEST(test_insert_n_value_position)
{

View File

@ -62,6 +62,11 @@ namespace
struct D1
{
D1()
: a("a")
{
}
D1(const std::string& a_)
: a(a_)
{
@ -72,9 +77,15 @@ namespace
struct D2
{
D2()
: a("a")
, b("b")
{
}
D2(const std::string& a_, const std::string& b_)
: a(a_),
b(b_)
: a(a_)
, b(b_)
{
}
@ -84,10 +95,17 @@ namespace
struct D3
{
D3()
: a("a")
, b("b")
, c("c")
{
}
D3(const std::string& a_, const std::string& b_, const std::string& c_)
: a(a_),
b(b_),
c(c_)
: a(a_)
, b(b_)
, c(c_)
{
}
@ -98,11 +116,19 @@ namespace
struct D4
{
D4()
: a("a")
, b("b")
, c("c")
, d("d")
{
}
D4(const std::string& a_, const std::string& b_, const std::string& c_, const std::string& d_)
: a(a_),
b(b_),
c(c_),
d(d_)
: a(a_)
, b(b_)
, c(c_)
, d(d_)
{
}
@ -582,6 +608,37 @@ namespace
CHECK(std::is_sorted(data.begin(), data.end()));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_default_value)
{
Compare1 compare;
Data1 data;
data.emplace();
compare.emplace();
data.emplace();
compare.emplace();
data.emplace();
compare.emplace();
// Do it again.
data.emplace();
compare.emplace();
data.emplace();
compare.emplace();
data.emplace();
compare.emplace();
CHECK_EQUAL(compare.size(), data.size());
bool isEqual = std::equal(data.begin(), data.end(), compare.begin());
CHECK(isEqual);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_value1)
{
@ -609,10 +666,7 @@ namespace
CHECK_EQUAL(compare.size(), data.size());
bool isEqual = std::equal(data.begin(),
data.end(),
compare.begin());
bool isEqual = std::equal(data.begin(), data.end(), compare.begin());
CHECK(isEqual);
}
@ -643,10 +697,7 @@ namespace
CHECK_EQUAL(compare.size(), data.size());
bool isEqual = std::equal(data.begin(),
data.end(),
compare.begin());
bool isEqual = std::equal(data.begin(), data.end(), compare.begin());
CHECK(isEqual);
}
@ -677,10 +728,7 @@ namespace
CHECK_EQUAL(compare.size(), data.size());
bool isEqual = std::equal(data.begin(),
data.end(),
compare.begin());
bool isEqual = std::equal(data.begin(), data.end(), compare.begin());
CHECK(isEqual);
}
@ -711,10 +759,7 @@ namespace
CHECK_EQUAL(compare.size(), data.size());
bool isEqual = std::equal(data.begin(),
data.end(),
compare.begin());
bool isEqual = std::equal(data.begin(), data.end(), compare.begin());
CHECK(isEqual);
}

View File

@ -94,6 +94,11 @@ namespace
struct D1
{
D1()
: a("a")
{
}
D1(const std::string& a_)
: a(a_)
{
@ -104,9 +109,15 @@ namespace
struct D2
{
D2()
: a("a")
, b("b")
{
}
D2(const std::string& a_, const std::string& b_)
: a(a_),
b(b_)
: a(a_)
, b(b_)
{
}
@ -116,10 +127,17 @@ namespace
struct D3
{
D3()
: a("a")
, b("b")
, c("c")
{
}
D3(const std::string& a_, const std::string& b_, const std::string& c_)
: a(a_),
b(b_),
c(c_)
: a(a_)
, b(b_)
, c(c_)
{
}
@ -130,11 +148,19 @@ namespace
struct D4
{
D4()
: a("a")
, b("b")
, c("c")
, d("d")
{
}
D4(const std::string& a_, const std::string& b_, const std::string& c_, const std::string& d_)
: a(a_),
b(b_),
c(c_),
d(d_)
: a(a_)
, b(b_)
, c(c_)
, d(d_)
{
}
@ -587,6 +613,34 @@ namespace
CHECK(std::is_sorted(data.begin(), data.end()));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_default_value)
{
Compare1 compare;
Data1 data;
data.emplace();
compare.emplace();
data.emplace();
compare.emplace();
data.emplace();
compare.emplace();
// Do it again.
data.emplace();
compare.emplace();
data.emplace();
compare.emplace();
data.emplace();
compare.emplace();
CHECK_EQUAL(compare.size(), data.size());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_value1)
{

View File

@ -692,6 +692,27 @@ namespace
CHECK_THROW(data.push_back(NDC("Z")), etl::vector_full);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_back_default_value)
{
CompareDataDC compare_data;
DataDC data;
for (size_t i = 0UL; i < SIZE; ++i)
{
compare_data.emplace_back();
data.emplace_back();
}
CHECK_EQUAL(compare_data.size(), data.size());
bool is_equal = std::equal(data.begin(),
data.end(),
compare_data.begin());
CHECK(is_equal);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_back)
{
@ -802,7 +823,6 @@ namespace
}
//*************************************************************************
// To test the CPP03 versions then ETL_TEST_VECTOR_CPP11 must be set to 0 in vector.h
TEST_FIXTURE(SetupFixture, test_emplace_back_multiple)
{
class Data
@ -965,6 +985,31 @@ namespace
}
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_position_default_value)
{
const size_t INITIAL_SIZE = 5UL;
for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset)
{
CompareDataDC compare_data;
DataDC data;
DC initial[] = { DC("0"), DC("1"), DC("2"), DC("3"), DC("4"), DC("4"), DC("4"), DC("5"), DC("6"), DC("7"), DC("8"), DC("9") };
data.assign(std::begin(initial), std::begin(initial) + INITIAL_SIZE);
compare_data.assign(std::begin(initial), std::begin(initial) + INITIAL_SIZE);
data.emplace(data.begin() + offset);
compare_data.emplace(compare_data.begin() + offset);
CHECK_EQUAL(compare_data.size(), data.size());
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(is_equal);
}
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_position_value)
{

View File

@ -561,47 +561,96 @@ namespace
CompareData compare_data(INITIAL_SIZE, VALUE);
DataNDC data(INITIAL_SIZE, VALUE);
size_t offset = 2UL;
//size_t offset = 2UL;
DataNDC::iterator i_data = data.begin();
std::advance(i_data, offset);
//std::advance(i_data, offset);
CompareData::iterator i_compare_data = compare_data.begin();
std::advance(i_compare_data, offset);
//CompareData::iterator i_compare_data = compare_data.begin();
//std::advance(i_compare_data, offset);
data.emplace(i_data, INSERT_VALUE);
compare_data.emplace(i_compare_data, INSERT_VALUE);
//compare_data.emplace(i_compare_data, INSERT_VALUE);
CHECK_EQUAL(compare_data.size(), data.size());
//CHECK_EQUAL(compare_data.size(), data.size());
are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
//are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(are_equal);
//CHECK(are_equal);
offset = 0;
//offset = 0;
i_data = data.begin();
std::advance(i_data, offset);
//i_data = data.begin();
//std::advance(i_data, offset);
i_compare_data = compare_data.begin();
std::advance(i_compare_data, offset);
//i_compare_data = compare_data.begin();
//std::advance(i_compare_data, offset);
data.emplace(i_data, INSERT_VALUE);
compare_data.emplace(i_compare_data, INSERT_VALUE);
//data.emplace(i_data, INSERT_VALUE);
//compare_data.emplace(i_compare_data, INSERT_VALUE);
are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
//are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(are_equal);
//CHECK(are_equal);
i_data = data.end();
i_compare_data = compare_data.end();
//i_data = data.end();
//i_compare_data = compare_data.end();
data.emplace(i_data, VALUE);
compare_data.emplace(i_compare_data, VALUE);
//data.emplace(i_data, VALUE);
//compare_data.emplace(i_compare_data, VALUE);
are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
//are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(are_equal);
//CHECK(are_equal);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_position_default_constructor)
{
//std::list<ItemDC> compare_data;
//DataDC data;
//size_t offset = 2UL;
//DataDC::iterator i_data = data.begin();
//std::advance(i_data, offset);
//std::list<ItemDC>::iterator i_compare_data = compare_data.begin();
//std::advance(i_compare_data, offset);
//data.emplace(i_data);
//compare_data.emplace(i_compare_data);
//CHECK_EQUAL(compare_data.size(), data.size());
//are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
//CHECK(are_equal);
//offset = 0;
//i_data = data.begin();
//std::advance(i_data, offset);
//i_compare_data = compare_data.begin();
//std::advance(i_compare_data, offset);
//data.emplace(i_data);
//compare_data.emplace(i_compare_data);
//are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
//CHECK(are_equal);
//i_data = data.end();
//i_compare_data = compare_data.end();
//data.emplace(i_data);
//compare_data.emplace(i_compare_data);
//are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
//CHECK(are_equal);
}
//*************************************************************************
@ -708,9 +757,10 @@ namespace
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_front)
{
CompareData compare_data;
DataNDC data;
std::list<ItemDC> compare_data;
etl::list<ItemDC, 7U> data;
compare_data.emplace_front();
compare_data.emplace_front("1");
compare_data.emplace_front("2");
compare_data.emplace_front("3");
@ -718,6 +768,7 @@ namespace
compare_data.emplace_front("5");
compare_data.emplace_front("6");
CHECK_NO_THROW(data.emplace_front());
CHECK_NO_THROW(data.emplace_front("1"));
CHECK_NO_THROW(data.emplace_front("2"));
CHECK_NO_THROW(data.emplace_front("3"));
@ -874,9 +925,10 @@ namespace
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_back)
{
CompareData compare_data;
DataNDC data;
std::list<ItemDC> compare_data;
etl::list<ItemDC, 7U> data;
compare_data.emplace_back();
compare_data.emplace_back("1");
compare_data.emplace_back("2");
compare_data.emplace_back("3");
@ -884,6 +936,7 @@ namespace
compare_data.emplace_back("5");
compare_data.emplace_back("6");
CHECK_NO_THROW(data.emplace_back());
CHECK_NO_THROW(data.emplace_back("1"));
CHECK_NO_THROW(data.emplace_back("2"));
CHECK_NO_THROW(data.emplace_back("3"));

View File

@ -125,6 +125,16 @@ namespace
CHECK_EQUAL(1, DataM::get_instance_count());
}
//*************************************************************************
TEST(test_emplace_zero_parameters)
{
etl::optional<std::uint8_t> result = 1;
result.emplace();
CHECK_TRUE(result.has_value());
CHECK_EQUAL(int(0), int(result.value()));
}
//*************************************************************************
TEST(test_moveable)
{
@ -503,6 +513,7 @@ namespace
return result;
}
//*************************************************************************
TEST(test_bug_634)
{
etl::optional<std::uint8_t> result;

View File

@ -42,10 +42,17 @@ namespace
struct Item
{
Item()
: c('a')
, i(1)
, d(1.2)
{
}
Item(char c_, int i_, double d_)
: c(c_),
i(i_),
d(d_)
: c(c_)
, i(i_)
, d(d_)
{
}
@ -344,9 +351,12 @@ namespace
//*************************************************************************
TEST(test_emplace)
{
etl::priority_queue<Item, SIZE> priority_queue;
etl::priority_queue<Item, 5> priority_queue;
std::priority_queue<Item> compare_priority_queue;
priority_queue.emplace();
compare_priority_queue.emplace();
priority_queue.emplace('d', 4, 7.8);
compare_priority_queue.emplace('d', 4, 7.8);

View File

@ -37,10 +37,17 @@ namespace
{
struct Item
{
Item()
: c('a')
, i(1)
, d(1.2)
{
}
Item(char c_, int i_, double d_)
: c(c_),
i(i_),
d(d_)
: c(c_)
, i(i_)
, d(d_)
{
}
@ -357,20 +364,23 @@ namespace
//*************************************************************************
TEST(test_multiple_emplace)
{
etl::queue<Item, 4> queue;
etl::queue<Item, 5> queue;
queue.emplace('a', 1, 1.2);
queue.emplace('b', 2, 3.4);
queue.emplace('c', 3, 5.6);
queue.emplace('d', 4, 7.8);
queue.emplace();
queue.emplace('b', 2, 2.3);
queue.emplace('c', 3, 3.4);
queue.emplace('d', 4, 4.5);
queue.emplace('e', 5, 5.6);
CHECK(queue.front() == Item('a', 1, 1.2));
queue.pop();
CHECK(queue.front() == Item('b', 2, 3.4));
CHECK(queue.front() == Item('b', 2, 2.3));
queue.pop();
CHECK(queue.front() == Item('c', 3, 5.6));
CHECK(queue.front() == Item('c', 3, 3.4));
queue.pop();
CHECK(queue.front() == Item('d', 4, 7.8));
CHECK(queue.front() == Item('d', 4, 4.5));
queue.pop();
CHECK(queue.front() == Item('e', 5, 5.6));
queue.pop();
}

View File

@ -552,10 +552,10 @@ namespace
{
QueueData queue;
queue.emplace();
queue.emplace(1);
queue.emplace(1, 2);
queue.emplace(1, 2, 3);
queue.emplace(1, 2, 3, 4);
CHECK(queue.called_lock);
CHECK(queue.called_unlock);
@ -564,7 +564,7 @@ namespace
Data popped;
queue.pop(popped);
CHECK(popped == Data(1, 2, 3, 4));
CHECK(popped == Data(0, 0, 0, 0));
queue.pop(popped);
CHECK(popped == Data(1, 2, 3, 4));
queue.pop(popped);

View File

@ -108,7 +108,7 @@ namespace
};
//***********************************
class QueueData : public etl::queue_lockable<Data, 4, etl::memory_model::MEMORY_MODEL_SMALL>
class QueueData : public etl::queue_lockable<Data, 5, etl::memory_model::MEMORY_MODEL_SMALL>
{
public:
@ -552,15 +552,20 @@ namespace
{
QueueData queue;
queue.emplace();
queue.emplace(1);
queue.emplace(1, 2);
queue.emplace(1, 2, 3);
queue.emplace(1, 2, 3, 4);
CHECK_EQUAL(4U, queue.size());
CHECK(queue.called_lock);
CHECK(queue.called_unlock);
CHECK_EQUAL(5U, queue.size());
Data popped;
queue.pop(popped);
CHECK(popped == Data(0, 0, 0, 0));
queue.pop(popped);
CHECK(popped == Data(1, 2, 3, 4));
queue.pop(popped);

View File

@ -36,6 +36,13 @@ namespace
{
struct Item
{
Item()
: c('a')
, i(1)
, d(1.2)
{
}
Item(char c_, int i_, double d_)
: c(c_),
i(i_),
@ -342,22 +349,23 @@ namespace
//*************************************************************************
TEST(test_multiple_emplace)
{
etl::queue<Item, 4> queue;
etl::queue<Item, 5> queue;
queue.emplace('a', 1, 1.2);
queue.emplace('b', 2, 3.4);
queue.emplace('c', 3, 5.6);
queue.emplace('d', 4, 7.8);
CHECK_EQUAL(4U, queue.size());
queue.emplace();
queue.emplace('b', 2, 2.3);
queue.emplace('c', 3, 3.4);
queue.emplace('d', 4, 4.5);
queue.emplace('e', 5, 5.6);
CHECK(queue.front() == Item('a', 1, 1.2));
queue.pop();
CHECK(queue.front() == Item('b', 2, 3.4));
CHECK(queue.front() == Item('b', 2, 2.3));
queue.pop();
CHECK(queue.front() == Item('c', 3, 5.6));
CHECK(queue.front() == Item('c', 3, 3.4));
queue.pop();
CHECK(queue.front() == Item('d', 4, 7.8));
CHECK(queue.front() == Item('d', 4, 4.5));
queue.pop();
CHECK(queue.front() == Item('e', 5, 5.6));
queue.pop();
}

View File

@ -193,17 +193,20 @@ namespace
//*************************************************************************
TEST(test_multiple_emplace)
{
etl::queue_mpmc_mutex<Data, 4> queue;
etl::queue_mpmc_mutex<Data, 5> queue;
queue.emplace();
queue.emplace(1);
queue.emplace(1, 2);
queue.emplace(1, 2, 3);
queue.emplace(1, 2, 3, 4);
CHECK_EQUAL(4U, queue.size());
CHECK_EQUAL(5U, queue.size());
Data popped;
queue.pop(popped);
CHECK(popped == Data(0, 0, 0, 0));
queue.pop(popped);
CHECK(popped == Data(1, 2, 3, 4));
queue.pop(popped);

View File

@ -205,17 +205,20 @@ namespace
//*************************************************************************
TEST(test_multiple_emplace)
{
etl::queue_mpmc_mutex<Data, 4, etl::memory_model::MEMORY_MODEL_SMALL> queue;
etl::queue_mpmc_mutex<Data, 5> queue;
queue.emplace();
queue.emplace(1);
queue.emplace(1, 2);
queue.emplace(1, 2, 3);
queue.emplace(1, 2, 3, 4);
CHECK_EQUAL(5U, queue.size());
Data popped;
CHECK_EQUAL(4U, queue.size());
queue.pop(popped);
CHECK(popped == Data(0, 0, 0, 0));
queue.pop(popped);
CHECK(popped == Data(1, 2, 3, 4));
queue.pop(popped);

View File

@ -312,17 +312,20 @@ namespace
//*************************************************************************
TEST(test_multiple_emplace)
{
etl::queue_spsc_atomic<Data, 4> queue;
etl::queue_spsc_atomic<Data, 5> queue;
queue.emplace();
queue.emplace(1);
queue.emplace(1, 2);
queue.emplace(1, 2, 3);
queue.emplace(1, 2, 3, 4);
CHECK_EQUAL(4U, queue.size());
CHECK_EQUAL(5U, queue.size());
Data popped;
queue.pop(popped);
CHECK(popped == Data(0, 0, 0, 0));
queue.pop(popped);
CHECK(popped == Data(1, 2, 3, 4));
queue.pop(popped);

View File

@ -330,17 +330,20 @@ namespace
//*************************************************************************
TEST(test_multiple_emplace)
{
etl::queue_spsc_atomic<Data, 4, etl::memory_model::MEMORY_MODEL_SMALL> queue;
etl::queue_spsc_atomic<Data, 5> queue;
queue.emplace();
queue.emplace(1);
queue.emplace(1, 2);
queue.emplace(1, 2, 3);
queue.emplace(1, 2, 3, 4);
CHECK_EQUAL(4U, queue.size());
CHECK_EQUAL(5U, queue.size());
Data popped;
queue.pop(popped);
CHECK(popped == Data(0, 0, 0, 0));
queue.pop(popped);
CHECK(popped == Data(1, 2, 3, 4));
queue.pop(popped);

View File

@ -74,18 +74,18 @@ namespace
struct Data
{
Data(int a_, int b_ = 2, int c_ = 3, int d_ = 4)
: a(a_),
b(b_),
c(c_),
d(d_)
: a(a_)
, b(b_)
, c(c_)
, d(d_)
{
}
Data()
: a(0),
b(0),
c(0),
d(0)
: a(0)
, b(0)
, c(0)
, d(0)
{
}
@ -496,17 +496,20 @@ namespace
//*************************************************************************
TEST(test_multiple_emplace)
{
etl::queue_spsc_isr<Data, 4, Access> queue;
etl::queue_spsc_isr<Data, 5, Access> queue;
queue.emplace();
queue.emplace(1);
queue.emplace(1, 2);
queue.emplace(1, 2, 3);
queue.emplace(1, 2, 3, 4);
CHECK_EQUAL(4U, queue.size());
CHECK_EQUAL(5U, queue.size());
Data popped;
queue.pop(popped);
CHECK(popped == Data(0, 0, 0, 0));
queue.pop(popped);
CHECK(popped == Data(1, 2, 3, 4));
queue.pop(popped);

View File

@ -74,18 +74,18 @@ namespace
struct Data
{
Data(int a_, int b_ = 2, int c_ = 3, int d_ = 4)
: a(a_),
b(b_),
c(c_),
d(d_)
: a(a_)
, b(b_)
, c(c_)
, d(d_)
{
}
Data()
: a(0),
b(0),
c(0),
d(0)
: a(0)
, b(0)
, c(0)
, d(0)
{
}
@ -514,17 +514,20 @@ namespace
//*************************************************************************
TEST(test_multiple_emplace)
{
etl::queue_spsc_isr<Data, 4, Access, etl::memory_model::MEMORY_MODEL_SMALL> queue;
etl::queue_spsc_isr<Data, 5, Access> queue;
queue.emplace();
queue.emplace(1);
queue.emplace(1, 2);
queue.emplace(1, 2, 3);
queue.emplace(1, 2, 3, 4);
CHECK_EQUAL(4U, queue.size());
CHECK_EQUAL(5U, queue.size());
Data popped;
queue.pop(popped);
CHECK(popped == Data(0, 0, 0, 0));
queue.pop(popped);
CHECK(popped == Data(1, 2, 3, 4));
queue.pop(popped);

View File

@ -77,18 +77,18 @@ namespace
struct Data
{
Data(int a_, int b_ = 2, int c_ = 3, int d_ = 4)
: a(a_),
b(b_),
c(c_),
d(d_)
: a(a_)
, b(b_)
, c(c_)
, d(d_)
{
}
Data()
: a(0),
b(0),
c(0),
d(0)
: a(0)
, b(0)
, c(0)
, d(0)
{
}
@ -501,17 +501,20 @@ namespace
//*************************************************************************
TEST(test_multiple_emplace)
{
etl::queue_spsc_locked<Data, 4> queue(lock, unlock);
etl::queue_spsc_locked<Data, 5> queue(lock, unlock);
queue.emplace();
queue.emplace(1);
queue.emplace(1, 2);
queue.emplace(1, 2, 3);
queue.emplace(1, 2, 3, 4);
CHECK_EQUAL(4U, queue.size());
CHECK_EQUAL(5U, queue.size());
Data popped;
queue.pop(popped);
CHECK(popped == Data(0, 0, 0, 0));
queue.pop(popped);
CHECK(popped == Data(1, 2, 3, 4));
queue.pop(popped);

View File

@ -518,17 +518,20 @@ namespace
//*************************************************************************
TEST(test_multiple_emplace)
{
etl::queue_spsc_locked<Data, 4, etl::memory_model::MEMORY_MODEL_SMALL> queue(lock, unlock);
etl::queue_spsc_locked<Data, 5, etl::memory_model::MEMORY_MODEL_SMALL> queue(lock, unlock);
queue.emplace();
queue.emplace(1);
queue.emplace(1, 2);
queue.emplace(1, 2, 3);
queue.emplace(1, 2, 3, 4);
CHECK_EQUAL(4U, queue.size());
CHECK_EQUAL(5U, queue.size());
Data popped;
queue.pop(popped);
CHECK(popped == Data(0, 0, 0, 0));
queue.pop(popped);
CHECK(popped == Data(1, 2, 3, 4));
queue.pop(popped);

View File

@ -38,10 +38,17 @@ namespace
{
struct Item
{
Item()
: c('a')
, i(1)
, d(1.2)
{
}
Item(char c_, int i_, double d_)
: c(c_),
i(i_),
d(d_)
: c(c_)
, i(i_)
, d(d_)
{
}
@ -219,25 +226,30 @@ namespace
//*************************************************************************
TEST(test_emplace)
{
etl::stack<Item, 4> stack;
etl::stack<Item, 5> stack;
stack.emplace('a', 1, 1.2);
stack.emplace();
CHECK_EQUAL(1U, stack.size());
stack.emplace('b', 2, 3.4);
stack.emplace('b', 2, 2.3);
CHECK_EQUAL(2U, stack.size());
stack.emplace('c', 3, 5.6);
stack.emplace('c', 3, 3.4);
CHECK_EQUAL(3U, stack.size());
stack.emplace('d', 4, 7.8);
stack.emplace('d', 4, 4.5);
CHECK_EQUAL(4U, stack.size());
CHECK(stack.top() == Item('d', 4, 7.8));
stack.emplace('e', 5, 5.6);
CHECK_EQUAL(5U, stack.size());
CHECK(stack.top() == Item('e', 5, 5.6));
stack.pop();
CHECK(stack.top() == Item('c', 3, 5.6));
CHECK(stack.top() == Item('d', 4, 4.5));
stack.pop();
CHECK(stack.top() == Item('b', 2, 3.4));
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));
}

View File

@ -795,6 +795,94 @@ namespace
}
}
//*************************************************************************
TEST(test_emplace_default)
{
const int Initial = 1;
const int Default = 2;
struct S
{
S()
: value(Default)
{
}
S(int v)
: value(v)
{
}
bool operator ==(const S& rhs) const
{
return value == rhs.value;
}
int value;
};
// First fill with Initial values.
etl::vector<S, SIZE> data;
data.resize(SIZE, S(Initial));
data.clear();
// Then emplace Default values.
for (size_t i = 0; i < SIZE; ++i)
{
data.emplace(data.end());
}
// Compare with an array of default values.
std::array<S, SIZE> compare_data;
compare_data.fill(S());
CHECK_TRUE(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
}
//*************************************************************************
TEST(test_emplace_back_default)
{
const int Initial = 1;
const int Default = 2;
struct S
{
S()
: value(Default)
{
}
S(int v)
: value(v)
{
}
bool operator ==(const S& rhs) const
{
return value == rhs.value;
}
int value;
};
// First fill with Initial values.
etl::vector<S, SIZE> data;
data.resize(SIZE, S(Initial));
data.clear();
// Then emplace Default values.
for (size_t i = 0; i < SIZE; ++i)
{
data.emplace_back();
}
// Compare with an array of default values.
std::array<S, SIZE> compare_data;
compare_data.fill(S());
CHECK_TRUE(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
}
//*************************************************************************
#include "etl/private/diagnostic_array_bounds_push.h"
TEST_FIXTURE(SetupFixture, test_insert_position_value_excess)

View File

@ -771,7 +771,6 @@ namespace
#endif
//*************************************************************************
// To test the CPP03 versions then ETL_TEST_VECTOR_CPP11 must be set to 0 in vector.h
TEST_FIXTURE(SetupFixture, test_emplace_back_multiple)
{
class Data

View File

@ -1068,6 +1068,52 @@ namespace
CHECK_EQUAL(&d2, data.emplace_back(&d2));
}
//*************************************************************************
TEST(test_emplace_default)
{
static int initial = 0;
// First fill with Initial values.
etl::vector<int*, SIZE> data;
data.resize(SIZE, &initial);
data.clear();
// Then emplace Default values.
for (size_t i = 0; i < SIZE; ++i)
{
data.emplace(data.begin());
}
// Compare with an array of default values.
std::array<int*, SIZE> compare_data;
compare_data.fill(nullptr);
CHECK_TRUE(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
}
//*************************************************************************
TEST(test_emplace_back_default)
{
static int initial = 0;
// First fill with initial values.
etl::vector<int*, SIZE> data;
data.resize(SIZE, &initial);
data.clear();
// Then emplace default values.
for (size_t i = 0; i < SIZE; ++i)
{
data.emplace_back();
}
// Compare with an array of default values.
std::array<int*, SIZE> compare_data;
compare_data.fill(nullptr);
CHECK_TRUE(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_pop_back)
{

View File

@ -17,6 +17,8 @@ Global
Debug MSVC C++17 - No STL|x64 = Debug MSVC C++17 - No STL|x64
Debug MSVC C++17|Win32 = Debug MSVC C++17|Win32
Debug MSVC C++17|x64 = Debug MSVC C++17|x64
Debug MSVC C++20 - Force C++03|Win32 = Debug MSVC C++20 - Force C++03|Win32
Debug MSVC C++20 - Force C++03|x64 = Debug MSVC C++20 - Force C++03|x64
Debug MSVC C++20 - No STL|Win32 = Debug MSVC C++20 - No STL|Win32
Debug MSVC C++20 - No STL|x64 = Debug MSVC C++20 - No STL|x64
Debug MSVC C++20 - No virtual messages|Win32 = Debug MSVC C++20 - No virtual messages|Win32
@ -49,6 +51,10 @@ Global
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++17|Win32.Build.0 = Debug MSVC C++17|Win32
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++17|x64.ActiveCfg = Debug MSVC C++17|x64
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++17|x64.Build.0 = Debug MSVC C++17|x64
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03|Win32.ActiveCfg = Debug MSVC C++20 - Force C++03|Win32
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03|Win32.Build.0 = Debug MSVC C++20 - Force C++03|Win32
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03|x64.ActiveCfg = Debug MSVC C++20 - Force C++03|x64
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03|x64.Build.0 = Debug MSVC C++20 - Force C++03|x64
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - No STL|Win32.ActiveCfg = Debug MSVC C++20 - No STL|Win32
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - No STL|Win32.Build.0 = Debug MSVC C++20 - No STL|Win32
{C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - No STL|x64.ActiveCfg = Debug MSVC C++20 - No STL|x64

File diff suppressed because it is too large Load Diff