From 622c949aeed30ef4d41ca4a01e70949b575d1799 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 21 Jun 2016 21:55:35 +0100 Subject: [PATCH] Removed C++ 03 incompatibilities. --- src/ivector.h | 99 ++++++++++++++++++++++----------------------------- 1 file changed, 43 insertions(+), 56 deletions(-) diff --git a/src/ivector.h b/src/ivector.h index 756b160e..cf015f81 100644 --- a/src/ivector.h +++ b/src/ivector.h @@ -76,6 +76,13 @@ namespace etl typedef typename parameter_type::type parameter_t; + private: + + template + struct no_construct : integral_constant::value || etl::is_pointer::value> + { + }; + public: //********************************************************************* @@ -650,81 +657,61 @@ namespace etl //********************************************************************* /// Create a new element with a default value at the back. //********************************************************************* - template - typename etl::enable_if::value, void>::type - create_element() + void create_element() { - current_size++; - } - - //********************************************************************* - /// Create a new element with a default value at the back. - //********************************************************************* - template - typename etl::enable_if::value, void>::type - create_element() - { - new(&p_buffer[current_size++]) T(); + if (no_construct::value) + { + current_size++; + } + else + { + new(&p_buffer[current_size++]) T(); + } } //********************************************************************* /// Create a new element with a value at the back //********************************************************************* - template - typename etl::enable_if::value, void>::type - create_element(parameter_t value) + void create_element(parameter_t value) { - p_buffer[current_size++] = value; - } - - //********************************************************************* - /// Create a new element with a value at the back - //********************************************************************* - template - typename etl::enable_if::value, void>::type - create_element(parameter_t value) - { - new(&p_buffer[current_size++]) T(value); + if (no_construct::value) + { + p_buffer[current_size++] = value; + } + else + { + new(&p_buffer[current_size++]) T(value); + } } //********************************************************************* /// Create a new element with a value at the index //********************************************************************* - template - typename etl::enable_if::value, void>::type - create_element_at(size_t index, parameter_t value) + void create_element_at(size_t index, parameter_t value) { - p_buffer[index] = value; - } - - //********************************************************************* - /// Create a new element with a value at the index - //********************************************************************* - template - typename etl::enable_if::value, void>::type - create_element_at(size_t index, parameter_t value) - { - new(&p_buffer[index]) T(value); + if (no_construct::value) + { + p_buffer[index] = value; + } + else + { + new(&p_buffer[index]) T(value); + } } //********************************************************************* /// Destroy an element at the back. //********************************************************************* - template - typename etl::enable_if::value, void>::type - destroy_element() + void destroy_element() { - --current_size; - } - - //********************************************************************* - /// Destroy an element at the back. - //********************************************************************* - template - typename etl::enable_if::value, void>::type - destroy_element() - { - p_buffer[--current_size].~U(); + if (no_construct::value) + { + --current_size; + } + else + { + p_buffer[--current_size].~T(); + } } // Disable copy construction.