diff --git a/include/etl/deque.h b/include/etl/deque.h index f44389e2..15ea7802 100644 --- a/include/etl/deque.h +++ b/include/etl/deque.h @@ -231,6 +231,9 @@ namespace etl typedef size_t size_type; typedef T& reference; typedef const T& const_reference; +#if ETL_CPP11_SUPPORTED + typedef T&& rvalue_reference; +#endif typedef T* pointer; typedef const T* const_pointer; typedef typename std::iterator_traits::difference_type difference_type; @@ -1621,7 +1624,7 @@ namespace etl /// 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(const T& item) + void push_back(const_reference item) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1635,7 +1638,7 @@ namespace etl /// 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) + void push_back(rvalue_reference item) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1749,7 +1752,7 @@ namespace etl /// 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(const T& item) + void push_front(const_reference item) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1763,7 +1766,7 @@ namespace etl /// 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) + void push_front(rvalue_reference item) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -2085,7 +2088,7 @@ namespace etl //********************************************************************* /// Create a new element with a default value at the front. //********************************************************************* - void create_element_front(const T& value) + void create_element_front(const_reference value) { --_begin; ::new (&(*_begin)) T(value); @@ -2096,7 +2099,7 @@ namespace etl //********************************************************************* /// Create a new element with a value at the back //********************************************************************* - void create_element_back(const T& value) + void create_element_back(const_reference value) { ::new (&(*_end)) T(value); ++_end; @@ -2108,7 +2111,7 @@ namespace etl //********************************************************************* /// Create a new element with a default value at the front. //********************************************************************* - void create_element_front(T&& value) + void create_element_front(rvalue_reference value) { --_begin; ::new (&(*_begin)) T(std::move(value)); @@ -2119,7 +2122,7 @@ namespace etl //********************************************************************* /// Create a new element with a value at the back //********************************************************************* - void create_element_back(T&& value) + void create_element_back(rvalue_reference value) { ::new (&(*_end)) T(std::move(value)); ++_end; @@ -2294,7 +2297,7 @@ namespace etl //************************************************************************* /// Assigns data to the deque. //************************************************************************* - explicit deque(size_t n, const T& value = value_type()) + explicit deque(size_t n, const_reference value = value_type()) : etl::ideque(reinterpret_cast(&buffer[0]), MAX_SIZE, BUFFER_SIZE) { this->assign(n, value); diff --git a/include/etl/flat_map.h b/include/etl/flat_map.h index 1d83deac..408669a2 100644 --- a/include/etl/flat_map.h +++ b/include/etl/flat_map.h @@ -76,6 +76,7 @@ namespace etl typedef TKeyCompare key_compare; typedef value_type& reference; typedef const value_type& const_reference; + typedef value_type&& rvalue_reference; typedef value_type* pointer; typedef const value_type* const_pointer; typedef size_t size_type; @@ -303,6 +304,31 @@ namespace etl return result; } + //********************************************************************* + /// Inserts a value to the flat_map. + /// If asserts or exceptions are enabled, emits flat_map_full if the flat_map is already full. + ///\param value The value to insert. + //********************************************************************* + std::pair insert(rvalue_reference value) + { + iterator i_element = lower_bound(value.first); + + std::pair result(i_element, false); + + // Doesn't already exist? + if ((i_element == end()) || compare(i_element->first, value.first) || compare(value.first, i_element->first)) + { + ETL_ASSERT(!refmap_t::full(), ETL_ERROR(flat_map_full)); + + value_type* pvalue = storage.allocate(); + ::new (pvalue) value_type(std::move(value)); + ETL_INCREMENT_DEBUG_COUNT + result = refmap_t::insert_at(i_element, *pvalue); + } + + return result; + } + //********************************************************************* /// Inserts a value to the flat_map. /// If asserts or exceptions are enabled, emits flat_map_full if the flat_map is already full. @@ -314,6 +340,17 @@ namespace etl return insert(value).first; } + //********************************************************************* + /// Inserts a value to the flat_map. + /// If asserts or exceptions are enabled, emits flat_map_full if the flat_map is already full. + ///\param position The position to insert at. + ///\param value The value to insert. + //********************************************************************* + iterator insert(iterator position, rvalue_reference value) + { + return insert(std::move(value)).first; + } + //********************************************************************* /// Inserts a range of values to the flat_map. /// If asserts or exceptions are enabled, emits flat_map_full if the flat_map does not have enough free space. diff --git a/include/etl/forward_list.h b/include/etl/forward_list.h index 9881a394..c46e4f65 100644 --- a/include/etl/forward_list.h +++ b/include/etl/forward_list.h @@ -46,7 +46,7 @@ SOFTWARE. #include "debug_count.h" #include "nullptr.h" #include "type_traits.h" -#include "parameter_type.h" +#include "memory.h" #if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include @@ -379,14 +379,12 @@ namespace etl protected: - typedef typename etl::parameter_type::type parameter_t; - //************************************************************************* /// The data node element in the forward_list. //************************************************************************* struct data_node_t : public node_t { - explicit data_node_t(parameter_t value_) + explicit data_node_t(const T& value_) : value(value_) {} @@ -688,7 +686,7 @@ namespace etl //************************************************************************* /// Assigns 'n' copies of a value to the forward_list. //************************************************************************* - void assign(size_t n, parameter_t value) + void assign(size_t n, const T& value) { ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(forward_list_full)); @@ -709,7 +707,7 @@ namespace etl //************************************************************************* /// Pushes a value to the front of the forward_list. //************************************************************************* - void push_front(parameter_t value) + void push_front(const T& value) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); @@ -719,6 +717,21 @@ namespace etl insert_node_after(start_node, data_node); } +#if ETL_CPP11_SUPPORTED + //************************************************************************* + /// Pushes a value to the front of the forward_list. + //************************************************************************* + void push_front(T&& value) + { +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); +#endif + + data_node_t& data_node = allocate_data_node(std::move(value)); + insert_node_after(start_node, data_node); + } +#endif + #if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Emplaces a value to the front of the list.. @@ -862,7 +875,7 @@ namespace etl //************************************************************************* /// Inserts a value to the forward_list after the specified position. //************************************************************************* - iterator insert_after(iterator position, parameter_t value) + iterator insert_after(iterator position, const T& value) { ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); @@ -872,6 +885,21 @@ namespace etl return iterator(&data_node); } +#if ETL_CPP11_SUPPORTED + //************************************************************************* + /// Inserts a value to the forward_list after the specified position. + //************************************************************************* + iterator insert_after(iterator position, T&& value) + { + ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); + + data_node_t& data_node = allocate_data_node(std::move(value)); + insert_node_after(*position.p_node, data_node); + + return iterator(&data_node); + } +#endif + #if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Emplaces a value to the forward_list after the specified position. @@ -957,7 +985,7 @@ namespace etl //************************************************************************* /// Inserts 'n' copies of a value to the forward_list after the specified position. //************************************************************************* - void insert_after(iterator position, size_t n, parameter_t value) + void insert_after(iterator position, size_t n, const T& value) { ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); @@ -1279,7 +1307,7 @@ namespace etl //************************************************************************* // Removes the values specified. //************************************************************************* - void remove(parameter_t value) + void remove(const T& value) { iterator i_item = begin(); iterator i_last_item = before_begin(); @@ -1438,7 +1466,7 @@ namespace etl //************************************************************************* /// Allocate a data_node_t. //************************************************************************* - data_node_t& allocate_data_node(parameter_t value) + data_node_t& allocate_data_node(const T& value) { data_node_t* p_node = p_node_pool->allocate(); ::new (&(p_node->value)) T(value); @@ -1447,6 +1475,20 @@ namespace etl return *p_node; } +#if ETL_CPP11_SUPPORTED + //************************************************************************* + /// Allocate a data_node_t. + //************************************************************************* + data_node_t& allocate_data_node(T&& value) + { + data_node_t* p_node = p_node_pool->allocate(); + ::new (&(p_node->value)) T(std::move(value)); + ETL_INCREMENT_DEBUG_COUNT + + return *p_node; + } +#endif + //************************************************************************* /// Destroy a data_node_t. //************************************************************************* @@ -1508,7 +1550,7 @@ namespace etl //************************************************************************* /// Construct from size and value. //************************************************************************* - explicit forward_list(size_t initial_size, typename etl::iforward_list::parameter_t value = T()) + explicit forward_list(size_t initial_size, const T& value = T()) : etl::iforward_list(node_pool, MAX_SIZE, false) { this->assign(initial_size, value); @@ -1618,7 +1660,7 @@ namespace etl //************************************************************************* /// Construct from size and value. //************************************************************************* - explicit forward_list(size_t initial_size, typename etl::iforward_list::parameter_t value, etl::ipool& node_pool) + explicit forward_list(size_t initial_size, const T& value, etl::ipool& node_pool) : etl::iforward_list(node_pool, node_pool.max_size(), true) { this->assign(initial_size, value); @@ -1633,6 +1675,17 @@ namespace etl this->assign(other.cbegin(), other.cend()); } +#if ETL_CPP11_SUPPORTED + //************************************************************************* + /// Move constructor. + //************************************************************************* + forward_list(forward_list&& other) + : etl::iforward_list(*other.p_node_pool, other.p_node_pool->max_size(), true) + { + //this->assign(other.cbegin(), other.cend()); + } +#endif + //************************************************************************* /// Construct from range. //************************************************************************* @@ -1675,6 +1728,21 @@ namespace etl return *this; } +#if ETL_CPP11_SUPPORTED + //************************************************************************* + /// Move assignment operator. + //************************************************************************* + forward_list& operator = (forward_list&& rhs) + { + if (&rhs != this) + { + //this->assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } +#endif + //************************************************************************* /// Set the pool instance. //************************************************************************* diff --git a/include/etl/list.h b/include/etl/list.h index 3d62eb17..2123bb23 100644 --- a/include/etl/list.h +++ b/include/etl/list.h @@ -418,7 +418,9 @@ namespace etl typedef const T* const_pointer; typedef T& reference; typedef const T& const_reference; +#if ETL_CPP11_SUPPORTED typedef T&& rvalue_reference; +#endif typedef size_t size_type; protected: @@ -1938,7 +1940,9 @@ namespace etl typedef const T* const_pointer; typedef T& reference; typedef const T& const_reference; +#if ETL_CPP11_SUPPORTED typedef T&& rvalue_reference; +#endif typedef size_t size_type; //************************************************************************* diff --git a/include/etl/memory.h b/include/etl/memory.h index b063dc1a..35c8cfb9 100644 --- a/include/etl/memory.h +++ b/include/etl/memory.h @@ -510,6 +510,7 @@ namespace etl return *reinterpret_cast(p); } +#if ETL_CPP11_SUPPORTED //***************************************************************************** /// Construct an item at address p. ///\ingroup memory @@ -520,6 +521,7 @@ namespace etl ::new (p) T(std::move(value)); return *reinterpret_cast(p); } +#endif //***************************************************************************** /// Construct an item at address p. diff --git a/include/etl/vector.h b/include/etl/vector.h index 8b3cf069..43eff53c 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -85,7 +85,9 @@ namespace etl typedef T value_type; typedef T& reference; typedef const T& const_reference; +#if ETL_CPP11_SUPPORTED typedef T&& rvalue_reference; +#endif typedef T* pointer; typedef const T* const_pointer; typedef T* iterator; diff --git a/include/etl/version.h b/include/etl/version.h index 71b9bf12..924846a0 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 14 #define ETL_VERSION_MINOR 7 -#define ETL_VERSION_PATCH 0 +#define ETL_VERSION_PATCH 1 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_WIDE_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH)) diff --git a/support/Release notes.txt b/support/Release notes.txt index 11d1c787..dd4dab1f 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +14.7.1 +Rvalue reference C++-03/C++11 compatibility fix. + =============================================================================== 14.7.0 Continuing updates for adding rvalue reference API to the containers.