From 740b08828221c0599dd5bfe4d431bf65d6e4611a Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Tue, 4 Nov 2014 20:33:11 +0000 Subject: [PATCH] Changes for compatibility with GCC --- container.h | 4 +- cyclic_value.h | 14 ++-- deque.h | 12 +-- ideque.h | 154 ++++++++++++++++++++------------------ ilist.h | 56 +++++++------- observer.h | 12 +-- static_assert.h | 4 +- test/test_array.cpp | 8 +- test/test_type_traits.cpp | 34 ++++++--- type_traits.h | 17 +++-- 10 files changed, 169 insertions(+), 146 deletions(-) diff --git a/container.h b/container.h index 637e668e..5cab2f6d 100644 --- a/container.h +++ b/container.h @@ -26,8 +26,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef __etl_array__ -#define __etl_array__ +#ifndef __etl_container__ +#define __etl_container__ #include diff --git a/cyclic_value.h b/cyclic_value.h index f59b4ca9..3f383d95 100644 --- a/cyclic_value.h +++ b/cyclic_value.h @@ -40,7 +40,7 @@ SOFTWARE. #include "static_assert.h" #include "exception.h" -namespace etl +namespace etl { #ifdef ETL_USE_EXCEPTIONS //*************************************************************************** @@ -123,9 +123,9 @@ namespace etl //************************************************************************* cyclic_value(const T& first_, const T& last_, const T& step_) : value(first_), - first_value(first_), - last_value(last_), - step_value(step_) + first_value(first_), + last_value(last_), + step_value(step_) { } @@ -288,7 +288,7 @@ namespace etl { return step_value; } - + //************************************************************************* /// Gets the number of steps in a cycle. //************************************************************************* @@ -299,10 +299,10 @@ namespace etl private: - T first_value; ///< The first value in the range. + T value; ///< The current value. + T first_value; ///< The first value in the range. T last_value; ///< The last value in the range. T step_value; ///< The value to step. - T value; ///< The current value. }; } diff --git a/deque.h b/deque.h index c13e2365..11d83eb6 100644 --- a/deque.h +++ b/deque.h @@ -54,7 +54,7 @@ namespace etl class deque : public ideque { public: - + static const size_t MAX_SIZE = MAX_SIZE_; private: @@ -70,7 +70,7 @@ namespace etl typedef const T& const_reference; typedef size_t size_type; typedef typename std::iterator_traits::difference_type difference_type; - + //************************************************************************* /// Default constructor. //************************************************************************* @@ -123,18 +123,18 @@ namespace etl void swap(deque& other) { // Swap the internal iterators. - first.swap(other.first); - last.swap(other.last); + this->first.swap(other.first); + this->last.swap(other.last); // Swap the other data. std::swap_ranges(etl::begin(buffer), etl::end(buffer), etl::begin(other.buffer)); - std::swap(current_size, other.current_size); + std::swap(this->current_size, other.current_size); } private: /// The buffer. - T buffer[BUFFER_SIZE]; + T buffer[BUFFER_SIZE]; }; } diff --git a/ideque.h b/ideque.h index 0899aab8..01b749e1 100644 --- a/ideque.h +++ b/ideque.h @@ -55,7 +55,7 @@ namespace etl typedef size_t size_type; typedef T value_type; typedef typename std::iterator_traits::difference_type difference_type; - + private: //************************************************************************* @@ -66,79 +66,25 @@ namespace etl { }; - //************************************************************************* - /// Iterator common parts. - //************************************************************************* - struct iterator_common - { - //*************************************************** - iterator_common() - : index(0), - p_buffer(nullptr), - p_deque(nullptr) - { - } - - //*************************************************** - iterator_common(difference_type index, - ideque& the_deque, - pointer p_buffer) - : index(index), - p_deque(&the_deque), - p_buffer(p_buffer) - { - } - - //*************************************************** - inline difference_type get_index() const - { - return index; - } - - //*************************************************** - inline ideque& get_deque() const - { - return *p_deque; - } - - //*************************************************** - inline pointer get_buffer() const - { - return p_buffer; - } - - //*************************************************** - void swap(iterator_common& other) - { - std::swap(index, other.index); - } - - protected: - - difference_type index; - pointer p_buffer; - ideque* p_deque; - }; - public: //************************************************************************* /// Iterator //************************************************************************* - struct iterator : public iterator_common, - public std::iterator + struct iterator : public std::iterator { friend class ideque; //*************************************************** iterator() - : iterator_common() { } //*************************************************** iterator(const iterator& other) - : iterator_common(other.index, *other.p_deque, other.p_buffer) + : index(other.index), + p_deque(other.p_deque), + p_buffer(other.p_buffer) { } @@ -171,7 +117,7 @@ namespace etl { operator -= (-offset); } - + return p_buffer[index]; } @@ -266,38 +212,70 @@ namespace etl return !(lhs == rhs); } + //*************************************************** + inline difference_type get_index() const + { + return index; + } + + //*************************************************** + inline ideque& get_deque() const + { + return *p_deque; + } + + //*************************************************** + inline pointer get_buffer() const + { + return p_buffer; + } + + //*************************************************** + void swap(iterator& other) + { + std::swap(index, other.index); + } + private: //*************************************************** iterator(difference_type index, ideque& the_deque, pointer p_buffer) - : iterator_common(index, the_deque, p_buffer) + : index(index), + p_deque(&the_deque), + p_buffer(p_buffer) { } + + difference_type index; + ideque* p_deque; + pointer p_buffer; }; //************************************************************************* /// Const Iterator //************************************************************************* - struct const_iterator : public iterator_common, - public std::iterator + struct const_iterator : public std::iterator { friend class ideque; //*************************************************** const_iterator() - : iterator_common() { } //*************************************************** const_iterator(const const_iterator& other) - : iterator_common(other.index, *other.p_deque, other.p_buffer) + : index(other.index), + p_deque(other.p_deque), + p_buffer(other.p_buffer) { } //*************************************************** const_iterator(const typename ideque::iterator& other) - : iterator_common(other.get_index(), other.get_deque(), other.get_buffer()) + : index(other.index), + p_deque(other.p_deque), + p_buffer(other.p_buffer) { } @@ -413,10 +391,34 @@ namespace etl return !(lhs == rhs); } + //*************************************************** + inline difference_type get_index() const + { + return index; + } + + //*************************************************** + inline ideque& get_deque() const + { + return *p_deque; + } + + //*************************************************** + inline pointer get_buffer() const + { + return p_buffer; + } + + //*************************************************** + void swap(const_iterator& other) + { + std::swap(index, other.index); + } + private: //*************************************************** - static difference_type distance(difference_type firstIndex, difference_type index) + difference_type distance(difference_type firstIndex, difference_type index) { if (index < firstIndex) { @@ -430,14 +432,20 @@ namespace etl //*************************************************** const_iterator(difference_type index, ideque& the_deque, pointer p_buffer) - : iterator_common(index, the_deque, p_buffer) + : index(index), + p_deque(&the_deque), + p_buffer(p_buffer) { } + + difference_type index; + ideque* p_deque; + pointer p_buffer; }; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - + //************************************************************************* /// Clears the deque. //************************************************************************* @@ -495,7 +503,7 @@ namespace etl { return ++const_iterator(last); } - + //************************************************************************* /// Gets a reverse iterator to the end of the deque. //************************************************************************* @@ -577,11 +585,11 @@ namespace etl clear(); std::fill_n(p_buffer, n, value); - + first.index = 0; last.index = n - 1; current_size = n; - } + } //************************************************************************* /// Resizes the deque. @@ -1265,7 +1273,7 @@ namespace etl template static difference_type distance(const TIterator1& range_begin, const TIterator2& range_end) { - difference_type distance1 = distance(range_begin); + difference_type distance1 = distance(range_begin); difference_type distance2 = distance(range_end); return distance2 - distance1; diff --git a/ilist.h b/ilist.h index 78d73d83..be1e0821 100644 --- a/ilist.h +++ b/ilist.h @@ -42,7 +42,7 @@ SOFTWARE. #include "nullptr.h" #include "list_base.h" -namespace etl +namespace etl { //*************************************************************************** /// A templated base for all etl::list types. @@ -86,7 +86,7 @@ namespace etl }; private: - + Node terminal_node; ///< The node that acts as the list start and end. Node* node_pool; ///< The pool of nodes used in the list. @@ -99,8 +99,6 @@ namespace etl typedef const T& const_reference; typedef size_t size_type; - typedef size_t size_type; ///< The type used for determining the size of list. - //************************************************************************* /// iterator. //************************************************************************* @@ -146,7 +144,7 @@ namespace etl iterator operator --(int) { - iterator temp(*this); + iterator temp(*this); p_node = p_node->previous; return temp; } @@ -257,7 +255,7 @@ namespace etl const_iterator operator --(int) { - const_iterator temp(*this); + const_iterator temp(*this); p_node = p_node->previous; return temp; } @@ -304,7 +302,7 @@ namespace etl }; typedef typename std::iterator_traits::difference_type difference_type; - + typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; @@ -461,7 +459,7 @@ namespace etl //************************************************************************* template void assign(TIterator first, TIterator last) - { + { #ifdef _DEBUG if (std::distance(first, last) < 0) { @@ -629,7 +627,7 @@ namespace etl void pop_front() { if (!empty()) - { + { remove_node(get_head()); } } @@ -790,7 +788,7 @@ namespace etl /// Erases a range of elements. //************************************************************************* iterator erase(iterator first, iterator last) - { + { Node* p_first = first.p_node; Node* p_last = last.p_node; Node* p_next; @@ -800,7 +798,7 @@ namespace etl // Erase the ones in between. while (p_first != p_last) - { + { // Update the position of the earliest free node in the pool. size_t new_free = std::distance(&node_pool[0], p_first); next_free = std::min(next_free, new_free); @@ -808,11 +806,11 @@ namespace etl // One less. --count; - p_next = p_first->next; // Remember the next node. + p_next = p_first->next; // Remember the next node. p_first->mark_as_free(); // Free the current node. p_first = p_next; // Move to the next node. } - + return last; } @@ -850,7 +848,7 @@ namespace etl /// Sort using in-place merge sort algorithm. /// Uses 'less-than operator as the predicate. //************************************************************************* - void sort() + void sort() { sort(std::less()); } @@ -861,7 +859,7 @@ namespace etl /// This is not my algorithm. I got it off the web somewhere. //************************************************************************* template - void sort(TCompare compare) + void sort(TCompare compare) { Node* p_left; Node* p_right; @@ -886,14 +884,14 @@ namespace etl number_of_merges = 0; // Count the number of merges we do in this pass. - while (p_left != &terminal_node) + while (p_left != &terminal_node) { ++number_of_merges; // There exists a merge to be done. p_right = p_left; left_size = 0; // Step 'list_size' places along from left - for (int i = 0; i < list_size; ++i) + for (int i = 0; i < list_size; ++i) { ++left_size; @@ -909,35 +907,35 @@ namespace etl right_size = list_size; // Now we have two lists. Merge them. - while (left_size > 0 || (right_size > 0 && p_right != &terminal_node)) + while (left_size > 0 || (right_size > 0 && p_right != &terminal_node)) { // Decide whether the next node of merge comes from left or right. - if (left_size == 0) + if (left_size == 0) { // Left is empty. The node must come from right. - p_node = p_right; - p_right = p_right->next; + p_node = p_right; + p_right = p_right->next; --right_size; - } + } else if (right_size == 0 || p_right == &terminal_node) { // Right is empty. The node must come from left. - p_node = p_left; - p_left = p_left->next; + p_node = p_left; + p_left = p_left->next; --left_size; } - else if (compare(p_left->value, p_right->value)) + else if (compare(p_left->value, p_right->value)) { // First node of left is lower or same. The node must come from left. - p_node = p_left; - p_left = p_left->next; + p_node = p_left; + p_left = p_left->next; --left_size; } else { // First node of right is lower. The node must come from right. - p_node = p_right; - p_right = p_right->next; + p_node = p_right; + p_right = p_right->next; --right_size; } diff --git a/observer.h b/observer.h index b2f214df..8751d00a 100644 --- a/observer.h +++ b/observer.h @@ -109,9 +109,9 @@ namespace etl void add_observer(TObserver& observer) { // See if we already have it in our list. - Observer_List::const_iterator i_observer = std::find(observer_list.begin(), - observer_list.end(), - &observer); + typename Observer_List::const_iterator i_observer = std::find(observer_list.begin(), + observer_list.end(), + &observer); // Not there? if (i_observer == observer_list.end()) @@ -138,9 +138,9 @@ namespace etl void remove_observer(TObserver& observer) { // See if we have it in our list. - Observer_List::iterator i_observer = std::find(observer_list.begin(), - observer_list.end(), - &observer); + typename Observer_List::iterator i_observer = std::find(observer_list.begin(), + observer_list.end(), + &observer); // Found it? if (i_observer != observer_list.end()) diff --git a/static_assert.h b/static_assert.h index df013239..846e1c5a 100644 --- a/static_assert.h +++ b/static_assert.h @@ -29,6 +29,8 @@ SOFTWARE. #if (WIN32) #define STATIC_ASSERT(Condition, Message) static_assert(Condition, Message) +#elif (__GNUG__) + #define STATIC_ASSERT(Condition, Message) static_assert(Condition, Message) #else template struct STATIC_ASSERTION_FAILURE; @@ -39,4 +41,4 @@ SOFTWARE. #define STATIC_ASSERT(Condition, Message) enum { assertdummy = sizeof(STATIC_ASSERTION_FAILURE<(bool)(Condition), Message>) } #endif -#endif \ No newline at end of file +#endif diff --git a/test/test_array.cpp b/test/test_array.cpp index 02c1f501..1573bcd5 100644 --- a/test/test_array.cpp +++ b/test/test_array.cpp @@ -32,8 +32,8 @@ SOFTWARE. #include #include -namespace -{ +namespace +{ SUITE(TestArray) { static const size_t SIZE = 10; @@ -57,7 +57,7 @@ namespace testData.assign(std::begin(n), std::end(n)); } }; - + //************************************************************************* TEST(DefaultConstructor) { @@ -308,4 +308,4 @@ namespace CHECK(data2 <= data); } }; -} \ No newline at end of file +} diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index 00d6673b..004b5d67 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -26,8 +26,22 @@ SOFTWARE. #include +#if (__GNUC__) +#define __GXX_EXPERIMENTAL_CXX0X__ +#endif + #include +#if (__GNUC__) +namespace std +{ + template + struct add_reference : public std::add_lvalue_reference + { + }; +} +#endif + #include "../type_traits.h" // A class to test non-fundamental types. @@ -228,7 +242,7 @@ namespace //************************************************************************* TEST(add_reference) { - CHECK((std::is_same::type, std::add_reference::type>::value)); + CHECK((std::is_same::type, std::add_lvalue_reference::type>::value)); CHECK((std::is_same::type, std::add_reference::type>::value)); CHECK((std::is_same::type, std::add_reference::type>::value)); CHECK((std::is_same::type, std::add_reference::type>::value)); @@ -270,7 +284,7 @@ namespace //************************************************************************* TEST(remove_volatile) - { + { CHECK((std::is_same::type, std::remove_volatile::type>::value)); CHECK((std::is_same::type, std::remove_volatile::type>::value)); CHECK((std::is_same::type, std::remove_volatile::type>::value)); @@ -278,7 +292,7 @@ namespace //************************************************************************* TEST(add_volatile) - { + { CHECK((std::is_same::type, std::add_volatile::type>::value)); CHECK((std::is_same::type, std::add_volatile::type>::value)); CHECK((std::is_same::type, std::add_volatile::type>::value)); @@ -286,7 +300,7 @@ namespace //************************************************************************* TEST(remove_cv) - { + { CHECK((std::is_same::type, std::remove_cv::type>::value)); CHECK((std::is_same::type, std::remove_cv::type>::value)); CHECK((std::is_same::type, std::remove_cv::type>::value)); @@ -295,7 +309,7 @@ namespace //************************************************************************* TEST(add_cv) - { + { typedef etl::add_cv::type t1; typedef std::add_cv::type t2; @@ -372,7 +386,7 @@ namespace //************************************************************************* TEST(is_void) - { + { CHECK(etl::is_void::value == std::is_void::value); CHECK(etl::is_void::value == std::is_void::value); } @@ -437,7 +451,7 @@ namespace //************************************************************************* TEST(remove_extent) - { + { CHECK((std::is_same::type, std::remove_extent::type>::value)); CHECK((std::is_same::type, std::remove_extent::type>::value)); CHECK((std::is_same::type, std::remove_extent::type>::value)); @@ -445,7 +459,7 @@ namespace //************************************************************************* TEST(remove_all_extents) - { + { CHECK((std::is_same::type, std::remove_all_extents::type>::value)); CHECK((std::is_same::type, std::remove_all_extents::type>::value)); CHECK((std::is_same::type, std::remove_all_extents::type>::value)); @@ -453,7 +467,7 @@ namespace //************************************************************************* TEST(rank) - { + { CHECK(etl::rank::value == std::rank::value); CHECK(etl::rank::value == std::rank::value); CHECK(etl::rank::value == std::rank::value); @@ -484,4 +498,4 @@ namespace CHECK_EQUAL(std::alignment_of::value, etl::alignment_of::value); } }; -} \ No newline at end of file +} diff --git a/type_traits.h b/type_traits.h index f02564a9..ae1b41dd 100644 --- a/type_traits.h +++ b/type_traits.h @@ -30,6 +30,7 @@ SOFTWARE. #define __etl_type_traits__ #include +#include "nullptr.h" ///\defgroup type_traits type_traits /// A set of type traits definitions for compilers that do not support the standard header. @@ -42,7 +43,7 @@ namespace etl template struct integral_constant { - static const T value = VALUE; + static const T value = VALUE; typedef T value_type; @@ -56,7 +57,7 @@ namespace etl ///\ingroup type_traits typedef integral_constant false_type; typedef integral_constant true_type; - + /// remove_reference ///\ingroup type_traits template struct remove_reference { typedef T type; }; @@ -200,7 +201,7 @@ namespace etl ///\ingroup type_traits template struct is_fundamental : integral_constant::value || is_void::value || - is_same::type>::value> {}; /// is_array @@ -261,16 +262,16 @@ namespace etl ///\ingroup type_traits template struct extent : std::integral_constant {}; - + template struct extent : std::integral_constant {}; - + template struct extent : std::integral_constant::value> {}; - + template struct extent : std::integral_constant {}; - + template struct extent : std::integral_constant::value> {}; @@ -291,7 +292,7 @@ namespace etl template struct rank : integral_constant {}; template struct rank : public integral_constant::value + 1> {}; template struct rank : public integral_constant::value + 1> {}; - + /// Alignment templates. /// These require compiler specific intrinsics. ///\ingroup type_traits