Changes for compatibility with GCC

This commit is contained in:
jwellbelove 2014-11-04 20:33:11 +00:00
parent 285983bee9
commit 740b088282
10 changed files with 169 additions and 146 deletions

View File

@ -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 <cstddef>

View File

@ -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.
};
}

12
deque.h
View File

@ -54,7 +54,7 @@ namespace etl
class deque : public ideque<T>
{
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<pointer>::difference_type difference_type;
//*************************************************************************
/// Default constructor.
//*************************************************************************
@ -123,18 +123,18 @@ namespace etl
void swap(deque<T, MAX_SIZE>& 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];
};
}

154
ideque.h
View File

@ -55,7 +55,7 @@ namespace etl
typedef size_t size_type;
typedef T value_type;
typedef typename std::iterator_traits<pointer>::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<std::random_access_iterator_tag, T>
struct iterator : public std::iterator<std::random_access_iterator_tag, T>
{
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<std::random_access_iterator_tag, const T>
struct const_iterator : public std::iterator<std::random_access_iterator_tag, const T>
{
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<iterator> reverse_iterator;
typedef std::reverse_iterator<const_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 <typename TIterator1, typename TIterator2>
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;

56
ilist.h
View File

@ -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<iterator>::difference_type difference_type;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
@ -461,7 +459,7 @@ namespace etl
//*************************************************************************
template <typename TIterator>
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<T>());
}
@ -861,7 +859,7 @@ namespace etl
/// This is not my algorithm. I got it off the web somewhere.
//*************************************************************************
template <typename TCompare>
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;
}

View File

@ -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())

View File

@ -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 <bool Condition, const char* Message>
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
#endif

View File

@ -32,8 +32,8 @@ SOFTWARE.
#include <vector>
#include <algorithm>
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);
}
};
}
}

View File

@ -26,8 +26,22 @@ SOFTWARE.
#include <UnitTest++/UnitTest++.h>
#if (__GNUC__)
#define __GXX_EXPERIMENTAL_CXX0X__
#endif
#include <type_traits>
#if (__GNUC__)
namespace std
{
template <typename T>
struct add_reference : public std::add_lvalue_reference<T>
{
};
}
#endif
#include "../type_traits.h"
// A class to test non-fundamental types.
@ -228,7 +242,7 @@ namespace
//*************************************************************************
TEST(add_reference)
{
CHECK((std::is_same<etl::add_reference<int>::type, std::add_reference<int>::type>::value));
CHECK((std::is_same<etl::add_reference<int>::type, std::add_lvalue_reference<int>::type>::value));
CHECK((std::is_same<etl::add_reference<int&>::type, std::add_reference<int&>::type>::value));
CHECK((std::is_same<etl::add_reference<const int&>::type, std::add_reference<const int&>::type>::value));
CHECK((std::is_same<etl::add_reference<volatile int&>::type, std::add_reference<volatile int&>::type>::value));
@ -270,7 +284,7 @@ namespace
//*************************************************************************
TEST(remove_volatile)
{
{
CHECK((std::is_same<etl::remove_volatile<int>::type, std::remove_volatile<int>::type>::value));
CHECK((std::is_same<etl::remove_volatile<volatile int>::type, std::remove_volatile<volatile int>::type>::value));
CHECK((std::is_same<etl::remove_volatile<const volatile int>::type, std::remove_volatile<const volatile int>::type>::value));
@ -278,7 +292,7 @@ namespace
//*************************************************************************
TEST(add_volatile)
{
{
CHECK((std::is_same<etl::add_volatile<int>::type, std::add_volatile<int>::type>::value));
CHECK((std::is_same<etl::add_volatile<volatile int>::type, std::add_volatile<volatile int>::type>::value));
CHECK((std::is_same<etl::add_volatile<const volatile int>::type, std::add_volatile<const volatile int>::type>::value));
@ -286,7 +300,7 @@ namespace
//*************************************************************************
TEST(remove_cv)
{
{
CHECK((std::is_same<etl::remove_cv<int>::type, std::remove_cv<int>::type>::value));
CHECK((std::is_same<etl::remove_cv<const int>::type, std::remove_cv<const int>::type>::value));
CHECK((std::is_same<etl::remove_cv<volatile int>::type, std::remove_cv<volatile int>::type>::value));
@ -295,7 +309,7 @@ namespace
//*************************************************************************
TEST(add_cv)
{
{
typedef etl::add_cv<int>::type t1;
typedef std::add_cv<int>::type t2;
@ -372,7 +386,7 @@ namespace
//*************************************************************************
TEST(is_void)
{
{
CHECK(etl::is_void<int>::value == std::is_void<int>::value);
CHECK(etl::is_void<void>::value == std::is_void<void>::value);
}
@ -437,7 +451,7 @@ namespace
//*************************************************************************
TEST(remove_extent)
{
{
CHECK((std::is_same<etl::remove_extent<int>::type, std::remove_extent<int>::type>::value));
CHECK((std::is_same<etl::remove_extent<int[]>::type, std::remove_extent<int[]>::type>::value));
CHECK((std::is_same<etl::remove_extent<int[10]>::type, std::remove_extent<int[10]>::type>::value));
@ -445,7 +459,7 @@ namespace
//*************************************************************************
TEST(remove_all_extents)
{
{
CHECK((std::is_same<etl::remove_all_extents<int>::type, std::remove_all_extents<int>::type>::value));
CHECK((std::is_same<etl::remove_all_extents<int[10]>::type, std::remove_all_extents<int[10]>::type>::value));
CHECK((std::is_same<etl::remove_all_extents<int[10][10]>::type, std::remove_all_extents<int[10][10]>::type>::value));
@ -453,7 +467,7 @@ namespace
//*************************************************************************
TEST(rank)
{
{
CHECK(etl::rank<int>::value == std::rank<int>::value);
CHECK(etl::rank<int[10]>::value == std::rank<int[10]>::value);
CHECK(etl::rank<int[10][10]>::value == std::rank<int[10][10]>::value);
@ -484,4 +498,4 @@ namespace
CHECK_EQUAL(std::alignment_of<Test>::value, etl::alignment_of<Test>::value);
}
};
}
}

View File

@ -30,6 +30,7 @@ SOFTWARE.
#define __etl_type_traits__
#include <cstddef>
#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 <typename T, const T VALUE>
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<bool, false> false_type;
typedef integral_constant<bool, true> true_type;
/// remove_reference
///\ingroup type_traits
template <typename T> struct remove_reference { typedef T type; };
@ -200,7 +201,7 @@ namespace etl
///\ingroup type_traits
template <typename T> struct is_fundamental : integral_constant<bool, is_arithmetic<T>::value ||
is_void<T>::value ||
is_same<nullptr_t,
is_same<std::nullptr_t,
typename remove_cv<T>::type>::value> {};
/// is_array
@ -261,16 +262,16 @@ namespace etl
///\ingroup type_traits
template <typename T, size_t N = 0>
struct extent : std::integral_constant<std::size_t, 0> {};
template <typename T>
struct extent<T[], 0> : std::integral_constant<std::size_t, 0> {};
template <typename T, size_t N>
struct extent<T[], N> : std::integral_constant<std::size_t, std::extent<T, N - 1>::value> {};
template <typename T, std::size_t N>
struct extent<T[N], 0> : std::integral_constant<std::size_t, N> {};
template <typename T, std::size_t I, size_t N>
struct extent<T[I], N> : std::integral_constant<std::size_t, std::extent<T, N - 1>::value> {};
@ -291,7 +292,7 @@ namespace etl
template <typename T>struct rank : integral_constant<std::size_t, 0> {};
template <typename T> struct rank<T[]> : public integral_constant<std::size_t, rank<T>::value + 1> {};
template <typename T, size_t N> struct rank<T[N]> : public integral_constant<std::size_t, rank<T>::value + 1> {};
/// Alignment templates.
/// These require compiler specific intrinsics.
///\ingroup type_traits