Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions include/etl/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ SOFTWARE.
#include "functional.h"
#include "utility.h"
#include "gcd.h"
#include "error_handler.h"
#include "exception.h"

#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -82,6 +84,27 @@ namespace etl

template <typename TIterator, typename TCompare>
ETL_CONSTEXPR14 void insertion_sort(TIterator first, TIterator last, TCompare compare);

class algorithm_exception : public etl::exception
{
public:

algorithm_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
: exception(reason_, file_name_, line_number_)
{
}
};

class algorithm_error : public algorithm_exception
{
public:

algorithm_error(string_type file_name_, numeric_type line_number_)
: algorithm_exception(ETL_ERROR_TEXT("algorithm:error", ETL_ALGORITHM_FILE_ID"A"), file_name_, line_number_)
{
}
};

}

//*****************************************************************************
Expand Down Expand Up @@ -2262,11 +2285,17 @@ namespace etl
TOutputIterator o_begin,
TOutputIterator o_end)
{
size_t s_size = etl::distance(i_begin, i_end);
size_t d_size = etl::distance(o_begin, o_end);
size_t size = (s_size < d_size) ? s_size : d_size;
using s_size_type = typename iterator_traits<TInputIterator>::difference_type;
using d_size_type = typename iterator_traits<TOutputIterator>::difference_type;
using min_size_type = typename etl::common_type<s_size_type, d_size_type>::type;

s_size_type s_size = etl::distance(i_begin, i_end);
ETL_ASSERT(s_size >= 0, ETL_ERROR(algorithm_error));
d_size_type d_size = etl::distance(o_begin, o_end);
ETL_ASSERT(d_size >= 0, ETL_ERROR(algorithm_error));
min_size_type size = etl::min<min_size_type>(s_size, d_size);

return etl::copy(i_begin, i_begin + size, o_begin);
return etl::copy(i_begin, i_begin + size, o_begin);
}

//***************************************************************************
Expand Down Expand Up @@ -2429,9 +2458,15 @@ namespace etl
TOutputIterator o_begin,
TOutputIterator o_end)
{
size_t s_size = etl::distance(i_begin, i_end);
size_t d_size = etl::distance(o_begin, o_end);
size_t size = (s_size < d_size) ? s_size : d_size;
using s_size_type = typename iterator_traits<TInputIterator>::difference_type;
using d_size_type = typename iterator_traits<TOutputIterator>::difference_type;
using min_size_type = typename etl::common_type<s_size_type, d_size_type>::type;

s_size_type s_size = etl::distance(i_begin, i_end);
ETL_ASSERT(s_size >= 0, ETL_ERROR(algorithm_error));
d_size_type d_size = etl::distance(o_begin, o_end);
ETL_ASSERT(d_size >= 0, ETL_ERROR(algorithm_error));
min_size_type size = etl::min<min_size_type>(s_size, d_size);

return etl::move(i_begin, i_begin + size, o_begin);
}
Expand Down
1 change: 1 addition & 0 deletions include/etl/file_error_numbers.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ SOFTWARE.
#define ETL_BASE64_FILE_ID "72"
#define ETL_SINGLETON_BASE_FILE_ID "73"
#define ETL_UNALIGNED_TYPE_FILE_ID "74"
#define ETL_ALGORITHM_FILE_ID "75"
#endif
23 changes: 0 additions & 23 deletions include/etl/intrusive_forward_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -991,29 +991,6 @@ namespace etl
}
}

//*************************************************************************
// Removes the element specified by pointer.
//*************************************************************************
void remove(const_pointer element)
{
iterator i_item = begin();
iterator i_last_item = before_begin();

while (i_item != end())
{
if (&i_item == element)
{
i_item = erase_after(i_last_item);
return;
}
else
{
++i_item;
++i_last_item;
}
}
}

//*************************************************************************
/// Removes according to a predicate.
//*************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion include/etl/intrusive_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace etl
public:

intrusive_list_value_is_already_linked(string_type file_name_, numeric_type line_number_)
: intrusive_list_exception(ETL_ERROR_TEXT("intrusive_list:value is already linked", ETL_INTRUSIVE_LIST_FILE_ID"E"), file_name_, line_number_)
: intrusive_list_exception(ETL_ERROR_TEXT("intrusive_list:value is already linked", ETL_INTRUSIVE_LIST_FILE_ID"D"), file_name_, line_number_)
{
}
};
Expand Down
4 changes: 2 additions & 2 deletions include/etl/private/bitset_new.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace etl
public:

bitset_overflow(string_type file_name_, numeric_type line_number_)
: bitset_exception(ETL_ERROR_TEXT("bitset:overflow", ETL_BITSET_FILE_ID"C"), file_name_, line_number_)
: bitset_exception(ETL_ERROR_TEXT("bitset:overflow", ETL_BITSET_FILE_ID"B"), file_name_, line_number_)
{
}
};
Expand All @@ -155,7 +155,7 @@ namespace etl
public:

bitset_invalid_buffer(string_type file_name_, numeric_type line_number_)
: bitset_exception(ETL_ERROR_TEXT("bitset:invalid buffer", ETL_BITSET_FILE_ID"D"), file_name_, line_number_)
: bitset_exception(ETL_ERROR_TEXT("bitset:invalid buffer", ETL_BITSET_FILE_ID"C"), file_name_, line_number_)
{
}
};
Expand Down
2 changes: 0 additions & 2 deletions include/etl/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ SOFTWARE.
#define ETL_QUEUE_INCLUDED

#include "platform.h"
#include "iterator.h"
#include "alignment.h"
#include "array.h"
#include "exception.h"
#include "error_handler.h"
#include "debug_count.h"
Expand Down
2 changes: 1 addition & 1 deletion include/etl/reference_flat_multiset.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace etl
public:

flat_multiset_iterator(string_type file_name_, numeric_type line_number_)
: flat_multiset_exception(ETL_ERROR_TEXT("flat_multiset:iterator", ETL_REFERENCE_FLAT_MULTISET_FILE_ID"C"), file_name_, line_number_)
: flat_multiset_exception(ETL_ERROR_TEXT("flat_multiset:iterator", ETL_REFERENCE_FLAT_MULTISET_FILE_ID"B"), file_name_, line_number_)
{
}
};
Expand Down
2 changes: 1 addition & 1 deletion include/etl/reference_flat_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace etl
public:

flat_set_iterator(string_type file_name_, numeric_type line_number_)
: flat_set_exception(ETL_ERROR_TEXT("flat_set:iterator", ETL_REFERENCE_FLAT_SET_FILE_ID"C"), file_name_, line_number_)
: flat_set_exception(ETL_ERROR_TEXT("flat_set:iterator", ETL_REFERENCE_FLAT_SET_FILE_ID"B"), file_name_, line_number_)
{
}
};
Expand Down
2 changes: 1 addition & 1 deletion include/etl/singleton_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace etl
public:

singleton_base_already_created(string_type file_name_, numeric_type line_number_)
: singleton_base_exception(ETL_ERROR_TEXT("singleton_base:already created", ETL_SINGLETON_BASE_FILE_ID"A"), file_name_, line_number_)
: singleton_base_exception(ETL_ERROR_TEXT("singleton_base:already created", ETL_SINGLETON_BASE_FILE_ID"B"), file_name_, line_number_)
{
}
};
Expand Down
11 changes: 11 additions & 0 deletions test/test_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,17 @@ namespace
CHECK(is_same);
}

//*************************************************************************
TEST(copy_s_random_iterator)
{
int data1[] = { 1, 2, 3, 4, 5 };
int out1[10];
CHECK_THROW(etl::copy_s(std::end(data1), std::begin(data1), std::begin(out1), std::end(out1)), etl::algorithm_error);
CHECK_THROW(etl::copy_s(std::begin(data1), std::end(data1), std::end(out1), std::begin(out1)), etl::algorithm_error);
CHECK_THROW(etl::move_s(std::end(data1), std::begin(data1), std::begin(out1), std::end(out1)), etl::algorithm_error);
CHECK_THROW(etl::move_s(std::begin(data1), std::end(data1), std::end(out1), std::begin(out1)), etl::algorithm_error);
}

//*************************************************************************
TEST(copy_4_parameter_non_random_iterator)
{
Expand Down
29 changes: 0 additions & 29 deletions test/test_intrusive_forward_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,35 +859,6 @@ namespace
CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end())));
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_remove_by_pointer)
{
std::forward_list<ItemNDCNode> compare_data(sorted_data.begin(), sorted_data.end());
DataNDC0 data0(sorted_data.begin(), sorted_data.end());
DataNDC1 data1(sorted_data.begin(), sorted_data.end());

auto it = data0.begin();
for (int i = 0; i < 7; ++i)
{
it++;
}
ItemNDCNode* element = &it;

compare_data.remove(ItemNDCNode("7"));
data0.remove(*element);

bool are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin());

CHECK(are_equal);
CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data0.size());
CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), std::distance(data0.begin(), data0.end()));

are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin());
CHECK(are_equal);
CHECK_EQUAL(sorted_data.size(), data1.size());
CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end())));
}

//*************************************************************************
TEST_FIXTURE(SetupFixture, test_remove_if)
{
Expand Down
Loading