Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development'
Browse files Browse the repository at this point in the history
# Conflicts:
#	include/etl/deque.h
#	include/etl/private/pvoidvector.h
#	include/etl/version.h
#	support/Release notes.txt
  • Loading branch information
jwellbelove committed Dec 16, 2018
1 parent f2f2339 commit dcb1e75
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 17 deletions.
155 changes: 155 additions & 0 deletions include/etl/deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SOFTWARE.

#include "stl/algorithm.h"
#include "stl/iterator.h"
#include "stl/utility.h"

#include "container.h"
#include "alignment.h"
Expand Down Expand Up @@ -916,6 +917,60 @@ namespace etl
return position;
}

#if ETL_CPP11_SUPPORTED
//*************************************************************************
/// Inserts data into the deque.
/// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is full.
///\param insert_position>The insert position.
///\param value>The value to insert.
//*************************************************************************
iterator insert(const_iterator insert_position, value_type&& value)
{
iterator position(insert_position.index, *this, p_buffer);

ETL_ASSERT(!full(), ETL_ERROR(deque_full));

if (insert_position == begin())
{
create_element_front(std::move(value));
position = _begin;
}
else if (insert_position == end())
{
create_element_back(std::move(value));
position = _end - 1;
}
else
{
// Are we closer to the front?
if (std::distance(_begin, position) < std::distance(position, _end - 1))
{
// Construct the _begin.
create_element_front(std::move(*_begin));

// Move the values.
std::move(_begin + 1, position, _begin);

// Write the new value.
*--position = std::move(value);
}
else
{
// Construct the _end.
create_element_back(std::move(*(_end - 1)));

// Move the values.
std::move_backward(position, _end - 2, _end - 1);

// Write the new value.
*position = std::move(value);
}
}

return position;
}
#endif

//*************************************************************************
/// Emplaces data into the deque.
/// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is full.
Expand Down Expand Up @@ -1577,6 +1632,21 @@ namespace etl
create_element_back(item);
}

#if ETL_CPP11_SUPPORTED
//*************************************************************************
/// Adds 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.
///\param item The item to push to the deque.
//*************************************************************************
void push_back(T&& item)
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(!full(), ETL_ERROR(deque_full));
#endif
create_element_back(std::move(item));
}
#endif

#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL)
//*************************************************************************
/// Emplaces an item to the back of the deque.
Expand Down Expand Up @@ -1690,6 +1760,21 @@ namespace etl
create_element_front(item);
}

#if ETL_CPP11_SUPPORTED
//*************************************************************************
/// Adds 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.
///\param item The item to push to the deque.
//*************************************************************************
void push_front(T&& item)
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(!full(), ETL_ERROR(deque_full));
#endif
create_element_front(std::move(item));
}
#endif

#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL)
//*************************************************************************
/// Emplaces an item to the front of the deque.
Expand Down Expand Up @@ -1999,6 +2084,30 @@ namespace etl
ETL_INCREMENT_DEBUG_COUNT
}

#if ETL_CPP11_SUPPORTED
//*********************************************************************
/// Create a new element with a default value at the front.
//*********************************************************************
void create_element_front(T&& value)
{
--_begin;
::new (&(*_begin)) T(std::move(value));
++current_size;
ETL_INCREMENT_DEBUG_COUNT
}

//*********************************************************************
/// Create a new element with a value at the back
//*********************************************************************
void create_element_back(T&& value)
{
::new (&(*_end)) T(std::move(value));
++_end;
++current_size;
ETL_INCREMENT_DEBUG_COUNT
}
#endif

//*********************************************************************
/// Destroy an element at the front.
//*********************************************************************
Expand Down Expand Up @@ -2129,6 +2238,29 @@ namespace etl
}
}

#if ETL_CPP11_SUPPORTED
//*************************************************************************
/// Move constructor.
//*************************************************************************
deque(deque&& other)
: etl::ideque<T>(reinterpret_cast<T*>(&buffer[0]), MAX_SIZE, BUFFER_SIZE)
{
if (this != &other)
{
this->initialise();

typename etl::ideque<T>::iterator itr = other.begin();
while (itr != other.end())
{
this->push_back(std::move(*itr));
++itr;
}

other.initialise();
}
}
#endif

//*************************************************************************
/// Assigns data to the deque.
//*************************************************************************
Expand Down Expand Up @@ -2172,6 +2304,29 @@ namespace etl
return *this;
}

#if ETL_CPP11_SUPPORTED
//*************************************************************************
/// Move assignment operator.
//*************************************************************************
deque& operator =(deque&& rhs)
{
if (&rhs != this)
{
this->clear();
typename etl::ideque<T>::iterator itr = rhs.begin();
while (itr != rhs.end())
{
this->push_back(std::move(*itr));
++itr;
}

rhs.initialise();
}

return *this;
}
#endif

//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
Expand Down
26 changes: 26 additions & 0 deletions include/etl/stl/alternate/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,32 @@ namespace std
return de;
}

//***************************************************************************
// move
template <typename TIterator1, typename TIterator2>
TIterator2 move(TIterator1 sb, TIterator1 se, TIterator2 db)
{
while (sb != se)
{
*db++ = std::move(*sb++);
}

return db;
}

//***************************************************************************
// move_backward
template <typename TIterator1, typename TIterator2>
TIterator2 move_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
{
while (sb != se)
{
*(--de) = std::move(*(--se));
}

return de;
}

//***************************************************************************
// lower_bound
template<typename TIterator, typename TValue, typename TCompare>
Expand Down
37 changes: 23 additions & 14 deletions include/etl/stl/alternate/utility.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
///\file
///\file

/******************************************************************************
The MIT License(MIT)
Expand Down Expand Up @@ -32,6 +32,7 @@ SOFTWARE.
#define ETL_STL_ALTERNATE_UTILITY_INCLUDED

#include "../../platform.h"
#include "../../type_traits.h"

#if defined(ETL_IN_UNIT_TEST)
#if !defined(ETLSTD)
Expand All @@ -48,7 +49,7 @@ SOFTWARE.
#if !defined(ETL_COMPILER_ARM6)
//******************************************************************************
template <typename T1, typename T2>
struct pair
struct pair
{
typedef T1 first_type;
typedef T2 second_type;
Expand All @@ -57,27 +58,27 @@ SOFTWARE.
T2 second;

pair()
: first(T1()),
second(T2())
: first(T1()),
second(T2())
{
}

pair(const T1& a, const T2& b)
: first(a),
pair(const T1& a, const T2& b)
: first(a),
second(b)
{
}

template <typename U1, typename U2>
pair(const pair<U1, U2>& other)
: first(other.first),
second(other.second)
pair(const pair<U1, U2>& other)
: first(other.first),
second(other.second)
{
}

pair(const pair<T1, T2>& other)
: first(other.first),
second(other.second)
pair(const pair<T1, T2>& other)
: first(other.first),
second(other.second)
{
}

Expand All @@ -99,7 +100,7 @@ SOFTWARE.
return pair<T1, T2>(a, b);
}

#if !defined(ETL_COMPILER_ARM6)
#if !defined(ETL_COMPILER_ARM6)
//******************************************************************************
template <typename T1, typename T2>
inline void swap(pair<T1, T2>& a, pair<T1, T2>& b)
Expand All @@ -121,7 +122,7 @@ SOFTWARE.
}

template <typename T1, typename T2>
inline bool operator <(const pair<T1, T2>& a, const pair<T1, T2>& b)
inline bool operator <(const pair<T1, T2>& a, const pair<T1, T2>& b)
{
return (a.first < b.first) ||
(!(b.first < a.first) && (a.second < b.second));
Expand All @@ -145,6 +146,14 @@ SOFTWARE.
return !(a < b);
}
#endif

#if ETL_CPP11_SUPPORTED
template <typename T>
constexpr typename etl::remove_reference<T>::type&& move(T&& t) noexcept
{
return static_cast<typename etl::remove_reference<T>::type&&>(t);
}
#endif
}

#endif
2 changes: 1 addition & 1 deletion include/etl/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ SOFTWARE.
///\ingroup utilities

#define ETL_VERSION_MAJOR 14
#define ETL_VERSION_MINOR 4
#define ETL_VERSION_MINOR 5
#define ETL_VERSION_PATCH 0

#define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH)
Expand Down
5 changes: 5 additions & 0 deletions support/Release notes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
===============================================================================
14.5.0
Added move algorithms and utility to 'alternate' STL.
Added rvalue reference API to etl::deque.

===============================================================================
14.4.0
Added C++03/C++11 emplace for deque, priority_queue, queues, stack, variant & vector.
Expand Down
Loading

0 comments on commit dcb1e75

Please sign in to comment.