Fix small issues

Move tests to test_iterator
This commit is contained in:
John Wellbelove 2022-10-04 18:42:14 +01:00
parent 445f950a82
commit a5c57521cb
7 changed files with 264 additions and 183 deletions

1
.gitignore vendored
View File

@ -360,3 +360,4 @@ test/etl_error_handler/build-exceptions_and_log_errors-GCC-Debug
test/etl_error_handler/build-exceptions-GCC-Debug
test/etl_error_handler/exceptions_and_log_errors/.vs
examples/ArmTimerCallbacks - C++/ArmTimerCallbacks.uvoptx
test/vs2022/.vs

View File

@ -34,6 +34,7 @@ SOFTWARE.
#include "platform.h"
#include "type_traits.h"
#include "utility.h"
#include "private/addressof.h"
#if ETL_USING_STL || defined(ETL_IN_UNIT_TEST)
#include <iterator>
@ -91,10 +92,8 @@ namespace etl
//***************************************************************************
// advance
#if ETL_NOT_USING_STL
template <typename TIterator, typename TDistance>
ETL_CONSTEXPR17 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::output_iterator_tag)
ETL_CONSTEXPR14 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::output_iterator_tag)
{
while (n--)
{
@ -103,7 +102,7 @@ namespace etl
}
template <typename TIterator, typename TDistance>
ETL_CONSTEXPR17 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::forward_iterator_tag)
ETL_CONSTEXPR14 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::forward_iterator_tag)
{
while (n--)
{
@ -112,7 +111,7 @@ namespace etl
}
template <typename TIterator, typename TDistance>
ETL_CONSTEXPR17 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::bidirectional_iterator_tag)
ETL_CONSTEXPR14 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::bidirectional_iterator_tag)
{
if (n > 0)
{
@ -131,34 +130,23 @@ namespace etl
}
template <typename TIterator, typename TDistance>
ETL_CONSTEXPR17 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::random_access_iterator_tag)
ETL_CONSTEXPR14 void advance_helper(TIterator& itr, TDistance n, ETL_OR_STD::random_access_iterator_tag)
{
itr += n;
}
template <typename TIterator, typename TDistance>
ETL_CONSTEXPR17 void advance(TIterator& itr, TDistance n)
ETL_CONSTEXPR14 void advance(TIterator& itr, TDistance n)
{
typedef typename etl::iterator_traits<TIterator>::iterator_category tag;
advance_helper(itr, n, tag());
}
#else
template <typename TIterator, typename TDistance>
ETL_CONSTEXPR17 void advance(TIterator& itr, TDistance n)
{
std::advance(itr, n);
}
#endif
//***************************************************************************
// distance
#if ETL_NOT_USING_STL
template<typename TIterator>
ETL_CONSTEXPR17 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::input_iterator_tag)
ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::input_iterator_tag)
{
typename etl::iterator_traits<TIterator>::difference_type d = 0;
@ -172,7 +160,7 @@ namespace etl
}
template<typename TIterator>
ETL_CONSTEXPR17 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::forward_iterator_tag)
ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::forward_iterator_tag)
{
typename etl::iterator_traits<TIterator>::difference_type d = 0;
@ -186,7 +174,7 @@ namespace etl
}
template<typename TIterator>
ETL_CONSTEXPR17 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::bidirectional_iterator_tag)
ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::bidirectional_iterator_tag)
{
typename etl::iterator_traits<TIterator>::difference_type d = 0;
@ -200,52 +188,36 @@ namespace etl
}
template<typename TIterator>
ETL_CONSTEXPR17 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::random_access_iterator_tag)
ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance_helper(TIterator first, TIterator last, ETL_OR_STD::random_access_iterator_tag)
{
return last - first;
}
template<typename TIterator>
ETL_CONSTEXPR17 typename etl::iterator_traits<TIterator>::difference_type distance(TIterator first, TIterator last)
ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type distance(TIterator first, TIterator last)
{
typedef typename etl::iterator_traits<TIterator>::iterator_category tag;
return distance_helper(first, last, tag());
}
#else
template<typename TIterator>
ETL_CONSTEXPR17 typename std::iterator_traits<TIterator>::difference_type distance(TIterator first, TIterator last)
{
return std::distance(first, last);
}
#endif
//***************************************************************************
// Previous
template<typename TIterator>
ETL_CONSTEXPR17 TIterator prev(TIterator itr, typename etl::iterator_traits<TIterator>::difference_type n = 1)
ETL_CONSTEXPR14 TIterator prev(TIterator itr, typename etl::iterator_traits<TIterator>::difference_type n = 1)
{
#if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
etl::advance(itr, -n);
#else
std::advance(itr, -n);
#endif
return itr;
}
//***************************************************************************
// Next
template<typename TIterator>
ETL_CONSTEXPR17 TIterator next(TIterator itr, typename etl::iterator_traits<TIterator>::difference_type n = 1)
ETL_CONSTEXPR14 TIterator next(TIterator itr, typename etl::iterator_traits<TIterator>::difference_type n = 1)
{
#if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
etl::advance(itr, n);
#else
std::advance(itr, n);
#endif
return itr;
}
@ -281,7 +253,7 @@ namespace etl
}
template<class TOther>
ETL_CONSTEXPR14 reverse_iterator& operator=(const reverse_iterator<TOther>& other)
ETL_CONSTEXPR14 reverse_iterator& operator =(const reverse_iterator<TOther>& other)
{
current = other.base();
@ -371,49 +343,49 @@ namespace etl
TIterator current;
};
template <class TIterator>
template <typename TIterator>
ETL_CONSTEXPR14 bool operator ==(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
{
return lhs.base() == rhs.base();
}
template <class TIterator>
template <typename TIterator>
ETL_CONSTEXPR14 bool operator !=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
{
return !(lhs == rhs);
}
template <class TIterator>
template <typename TIterator>
ETL_CONSTEXPR14 bool operator <(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
{
return rhs.base() < lhs.base();
}
template <class TIterator>
template <typename TIterator>
ETL_CONSTEXPR14 bool operator >(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
{
return rhs < lhs;
}
template <class TIterator>
template <typename TIterator>
ETL_CONSTEXPR14 bool operator <=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
{
return !(rhs < lhs);
}
template <class TIterator>
template <typename TIterator>
ETL_CONSTEXPR14 bool operator >=(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
{
return !(lhs < rhs);
}
template <class TIterator>
template <typename TIterator>
ETL_CONSTEXPR14 typename reverse_iterator<TIterator>::difference_type operator -(const reverse_iterator<TIterator>& lhs, const reverse_iterator<TIterator>& rhs)
{
return rhs.base() - lhs.base();
}
template <class TIterator, class TDifference>
template <typename TIterator, class TDifference>
ETL_CONSTEXPR14 reverse_iterator<TIterator> operator +(TDifference n, const reverse_iterator<TIterator>& itr)
{
return itr.operator +(n);
@ -610,184 +582,219 @@ namespace etl
// back_insert_iterator
//***************************************************************************
/**
* @brief Turns assignment into insertion.
*
* These are output iterators, constructed from a container-of-T.
* Assigning a T to the iterator appends it to the container using push_back.
*
* @tparam TContainer
*/
template <class TContainer>
class back_insert_iterator : public iterator<output_iterator_tag, void, void, void, void>
//***************************************************************************
///\brief Turns assignment into insertion.
///
/// These are output iterators, constructed from a container-of-T.
/// Assigning a T to the iterator appends it to the container using push_back.
///
/// @tparam TContainer
//***************************************************************************
template <typename TContainer>
class back_insert_iterator : public etl::iterator<ETL_OR_STD::output_iterator_tag, void, void, void, void>
{
public:
/// A nested typedef for the type of whatever container you used.
typedef TContainer container_type;
/// The only way to create this %iterator is with a container.
explicit ETL_CONSTEXPR17 back_insert_iterator(TContainer& c)
explicit ETL_CONSTEXPR14 back_insert_iterator(TContainer& c)
: container(etl::addressof(c))
{
}
/**
* This kind of %iterator doesn't really have a @a position in the
* container (you can think of the position as being permanently at
* the end, if you like). Assigning a value to the %iterator will
* always append the value to the end of the container.
*
* @param value An instance of whatever type container_type::const_reference is;
* presumably a reference-to-const T for container<T>.
* @return This %iterator, for chained operations.
*/
ETL_CONSTEXPR17 back_insert_iterator& operator=(const typename TContainer::value_type& value)
//***************************************************************************
/// This kind of %iterator doesn't really have a @a position in the
/// container (you can think of the position as being permanently at
/// the end, if you like). Assigning a value to the %iterator will
/// always append the value to the end of the container.
///
/// @param value An instance of whatever type container_type::const_reference is;
/// presumably a reference-to-const T for container<T>.
/// @return This %iterator, for chained operations.
//***************************************************************************
ETL_CONSTEXPR14 back_insert_iterator& operator =(const typename TContainer::value_type& value)
{
container->push_back(value);
return (*this);
}
#if ETL_USING_CPP11
ETL_CONSTEXPR17 back_insert_iterator& operator=(typename TContainer::reference value)
//***************************************************************************
/// Move assignment operator.
//***************************************************************************
ETL_CONSTEXPR14 back_insert_iterator& operator =(typename TContainer::value_type&& value)
{
container->push_back(etl::move(value));
return (*this);
}
#endif // ETL_USING_CPP11
//***************************************************************************
/// Dereference operator.
/// Simply returns *this.
ETL_NODISCARD ETL_CONSTEXPR17 back_insert_iterator& operator*()
//***************************************************************************
ETL_NODISCARD ETL_CONSTEXPR14 back_insert_iterator& operator *()
{
return (*this);
}
//***************************************************************************
/// Pre-increment operator.
/// Simply returns *this. (This %iterator does not @a move.)
ETL_CONSTEXPR17 back_insert_iterator& operator++()
//***************************************************************************
ETL_CONSTEXPR14 back_insert_iterator& operator ++()
{
return (*this);
}
//***************************************************************************
/// Post-increment operator.
/// Simply returns *this. (This %iterator does not @a move.)
ETL_CONSTEXPR17 back_insert_iterator operator++(int)
//***************************************************************************
ETL_CONSTEXPR14 back_insert_iterator operator ++(int)
{
return (*this);
}
protected:
TContainer* container;
};
/**
* This wrapper function helps in creating back_insert_iterator instances.
* Typing the name of the %iterator requires knowing the precise full
* type of the container, which can be tedious and impedes generic
* programming. Using this function lets you take advantage of automatic
* template parameter deduction, making the compiler match the correct types for you.
*
* @tparam TContainer The container type.
* @param container A container of arbitrary type.
* @return An instance of back_insert_iterator working on @p container.
*/
template <class TContainer>
ETL_NODISCARD ETL_CONSTEXPR17 inline ETL_OR_STD::back_insert_iterator<TContainer> back_inserter(TContainer& container)
//***************************************************************************
/// This wrapper function helps in creating back_insert_iterator instances.
/// Typing the name of the %iterator requires knowing the precise full
/// type of the container, which can be tedious and impedes generic
/// programming. Using this function lets you take advantage of automatic
/// template parameter deduction, making the compiler match the correct types for you.
///
/// @tparam TContainer The container type.
/// @param container A container of arbitrary type.
/// @return An instance of back_insert_iterator working on @p container.
//***************************************************************************
template <typename TContainer>
ETL_NODISCARD
ETL_CONSTEXPR14
etl::back_insert_iterator<TContainer> back_inserter(TContainer& container)
{
return ETL_OR_STD::back_insert_iterator<TContainer>(container);
return etl::back_insert_iterator<TContainer>(container);
}
//***************************************************************************
// front_insert_iterator
//***************************************************************************
/**
* @brief Turns assignment into insertion.
*
* These are output iterators, constructed from a container-of-T.
* Assigning a T to the iterator prepends it to the container using
* push_front.
*
* Tip: Using the front_inserter function to create these iterators can
* save typing.
*
* @tparam TContainer The container type.
*/
//***************************************************************************
///\brief Turns assignment into insertion.
///
/// These are output iterators, constructed from a container-of-T.
/// Assigning a T to the iterator prepends it to the container using
/// push_front.
///
/// Tip: Using the front_inserter function to create these iterators can
/// save typing.
///
///\tparam TContainer The container type.
//***************************************************************************
template <typename TContainer>
class front_insert_iterator
: public iterator<output_iterator_tag, void, void, void, void>
class front_insert_iterator : public etl::iterator<ETL_OR_STD::output_iterator_tag, void, void, void, void>
{
public:
/// A nested typedef for the type of whatever container you used.
typedef TContainer container_type;
//***************************************************************************
/// Constructor
/// The only way to create this %iterator is with a container.
explicit ETL_CONSTEXPR17 front_insert_iterator(TContainer& c)
//***************************************************************************
explicit ETL_CONSTEXPR14 front_insert_iterator(TContainer& c)
: container(etl::addressof(c))
{
}
/**
* This kind of %iterator doesn't really have a @a position in the
* container (you can think of the position as being permanently at
* the front, if you like). Assigning a value to the %iterator will
* always prepend the value to the front of the container.
*
* @param value An instance of whatever type
* container_type::const_reference is; presumably a
* reference-to-const T for container<T>.
* @return This %iterator, for chained operations.
*
*/
ETL_CONSTEXPR17 front_insert_iterator& operator=(const typename TContainer::value_type& value)
//***************************************************************************
/// This kind of %iterator doesn't really have a @a position in the
/// container (you can think of the position as being permanently at
/// the front, if you like). Assigning a value to the %iterator will
/// always prepend the value to the front of the container.
///
/// @param value An instance of whatever type
/// container_type::const_reference is; presumably a
/// reference-to-const T for container<T>.
/// @return This %iterator, for chained operations.
//***************************************************************************
ETL_CONSTEXPR14 front_insert_iterator& operator =(const typename TContainer::value_type& value)
{
container->push_front(value);
return (*this);
}
#if ETL_USING_CPP11
ETL_CONSTEXPR17 front_insert_iterator& operator=(typename TContainer::reference value)
//***************************************************************************
/// Move assignment operator.
//***************************************************************************
ETL_CONSTEXPR14 front_insert_iterator& operator =(typename TContainer::value_type&& value)
{
container->push_front(etl::move(value));
return (*this);
}
#endif // ETL_USING_CPP11
//***************************************************************************
/// Dereference operator.
/// Simply returns *this.
ETL_NODISCARD ETL_CONSTEXPR17 front_insert_iterator& operator*()
//***************************************************************************
ETL_NODISCARD ETL_CONSTEXPR14 front_insert_iterator& operator *()
{
return (*this);
}
//***************************************************************************
/// Pre-increment operator.
/// Simply returns *this. (This %iterator does not @a move.)
ETL_CONSTEXPR17 front_insert_iterator& operator++()
//***************************************************************************
ETL_CONSTEXPR14 front_insert_iterator& operator ++()
{
return (*this);
}
//***************************************************************************
/// Post-increment operator.
/// Simply returns *this. (This %iterator does not @a move.)
ETL_CONSTEXPR17 front_insert_iterator operator++(int)
//***************************************************************************
ETL_CONSTEXPR14 front_insert_iterator operator ++(int)
{
return (*this);
}
protected:
TContainer* container;
};
/**
* This wrapper function helps in creating front_insert_iterator instances.
* Typing the name of the %iterator requires knowing the precise full
* type of the container, which can be tedious and impedes generic
* programming. Using this function lets you take advantage of automatic
* template parameter deduction, making the compiler match the correct
* types for you.
*
* @tparam TContainer The container type.
* @param container A container of arbitrary type.
* @return An instance of front_insert_iterator working on @p x.
*/
//***************************************************************************
/// This wrapper function helps in creating front_insert_iterator instances.
/// Typing the name of the %iterator requires knowing the precise full
/// type of the container, which can be tedious and impedes generic
/// programming. Using this function lets you take advantage of automatic
/// template parameter deduction, making the compiler match the correct
/// types for you.
///
///\tparam TContainer The container type.
///\param container A container of arbitrary type.
///\return An instance of front_insert_iterator working on @p x.
//***************************************************************************
template <typename TContainer>
ETL_NODISCARD ETL_CONSTEXPR17 inline ETL_OR_STD::front_insert_iterator<TContainer> front_inserter(TContainer& container)
ETL_NODISCARD
ETL_CONSTEXPR14
etl::front_insert_iterator<TContainer> front_inserter(TContainer& container)
{
return ETL_OR_STD::front_insert_iterator<TContainer>(container);
return etl::front_insert_iterator<TContainer>(container);
}
//***************************************************************************

View File

@ -39,6 +39,7 @@ SOFTWARE.
#include "nullptr.h"
#include "alignment.h"
#include "placement_new.h"
#include "private/addressof.h"
#include <assert.h>
#include <string.h>
@ -52,21 +53,6 @@ SOFTWARE.
namespace etl
{
//*****************************************************************************
/// Gets the address of an object.
/// https://en.cppreference.com/w/cpp/memory/addressof
///\ingroup memory
//*****************************************************************************
template <typename T>
ETL_CONSTEXPR17 T* addressof(T& t)
{
#if ETL_USING_STL && ETL_USING_CPP11
return std::addressof(t);
#else
return reinterpret_cast<T*>(&const_cast<char&>(reinterpret_cast<const volatile char&>(t)));
#endif
}
#if ETL_NOT_USING_STL
//*****************************************************************************
/// Fills uninitialised memory range with a value.

View File

@ -0,0 +1,61 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2022 John Wellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#ifndef ETL_ADDRESSOF_INCLUDED
#define ETL_ADDRESSOF_INCLUDED
#include "../platform.h"
#if defined(ETL_IN_UNIT_TEST) || ETL_USING_STL
#include <memory>
#endif
///\defgroup memory memory
///\ingroup etl
namespace etl
{
//*****************************************************************************
/// Gets the address of an object.
/// https://en.cppreference.com/w/cpp/memory/addressof
///\ingroup memory
//*****************************************************************************
template <typename T>
ETL_CONSTEXPR17 T* addressof(T& t)
{
#if ETL_USING_STL && ETL_USING_CPP11
return std::addressof(t);
#else
return reinterpret_cast<T*>(&const_cast<char&>(reinterpret_cast<const volatile char&>(t)));
#endif
}
}
#endif

View File

@ -29,6 +29,8 @@ SOFTWARE.
#include "unit_test_framework.h"
#include <string>
#include <list>
#include <algorithm>
#include "etl/iterator.h"
@ -276,7 +278,7 @@ namespace
CHECK_EQUAL(*sri, *eri);
}
//*************************************************************************
TEST(test_input)
{
CHECK(!!etl::is_input_iterator<input>::value);
@ -292,6 +294,7 @@ namespace
CHECK(!etl::is_random_iterator_concept<input>::value);
}
//*************************************************************************
TEST(test_output)
{
CHECK(!etl::is_input_iterator<output>::value);
@ -307,6 +310,7 @@ namespace
CHECK(!etl::is_random_iterator_concept<output>::value);
}
//*************************************************************************
TEST(test_forward)
{
CHECK(!etl::is_input_iterator<forward>::value);
@ -322,6 +326,7 @@ namespace
CHECK(!etl::is_random_iterator_concept<forward>::value);
}
//*************************************************************************
TEST(test_bidirectional)
{
CHECK(!etl::is_input_iterator<bidirectional>::value);
@ -337,6 +342,7 @@ namespace
CHECK(!etl::is_random_iterator_concept<bidirectional>::value);
}
//*************************************************************************
TEST(test_random)
{
CHECK(!etl::is_input_iterator<random>::value);
@ -352,6 +358,7 @@ namespace
CHECK(!!etl::is_random_iterator_concept<random>::value);
}
//*************************************************************************
TEST(test_pointer)
{
CHECK(!etl::is_input_iterator<pointer>::value);
@ -367,6 +374,7 @@ namespace
CHECK(!!etl::is_random_iterator_concept<pointer>::value);
}
//*************************************************************************
TEST(test_const_pointer)
{
CHECK(!etl::is_input_iterator<const_pointer>::value);
@ -383,7 +391,7 @@ namespace
}
//*************************************************************************
TEST(move_iterator_constructors)
TEST(test_move_iterator_constructors)
{
Item list[] = { Item("1"), Item("2"), Item("3") };
@ -402,7 +410,7 @@ namespace
}
//*************************************************************************
TEST(move_iterator_relational_operators)
TEST(test_move_iterator_relational_operators)
{
Item list[] = { Item("1"), Item("2"), Item("3") };
@ -434,7 +442,7 @@ namespace
}
//*************************************************************************
TEST(move_iterator_access_operators)
TEST(test_move_iterator_access_operators)
{
Item item1("1");
@ -455,7 +463,7 @@ namespace
}
//*************************************************************************
TEST(move_iterator_index)
TEST(test_move_iterator_index)
{
Item list[] = { Item("1"), Item("2"), Item("3") };
@ -466,7 +474,7 @@ namespace
}
//*************************************************************************
TEST(move_iterator_increment_decrement)
TEST(test_move_iterator_increment_decrement)
{
Item list[] = { Item("1"), Item("2"), Item("3") };
@ -506,7 +514,7 @@ namespace
}
//*************************************************************************
TEST(move_iterator_subtraction)
TEST(test_move_iterator_subtraction)
{
Item list[] = { Item("1"), Item("2"), Item("3") };
@ -517,5 +525,41 @@ namespace
CHECK_EQUAL(1, d);
}
//*************************************************************************
TEST(test_front_insert_iterator)
{
std::list<int> input = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
std::list<int> expected = { 81, 64, 49, 36, 25, 16, 9, 4, 1, 0 };
std::list<int> output;
auto squared = [](int value)
{
return value * value;
};
std::transform(input.cbegin(), input.cend(), etl::front_inserter(output), squared);
CHECK_EQUAL(expected.size(), output.size());
CHECK(std::equal(output.begin(), output.end(), expected.begin()));
}
//*************************************************************************
TEST(test_back_insert_iterator)
{
std::list<int> input = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
std::list<int> expected = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 };
std::list<int> output;
auto squared = [](int value)
{
return value * value;
};
std::transform(input.cbegin(), input.cend(), etl::back_inserter(output), squared);
CHECK_EQUAL(expected.size(), output.size());
CHECK(std::equal(output.begin(), output.end(), expected.begin()));
}
};
}

View File

@ -357,8 +357,10 @@ namespace
auto selector = etl::select1st<EtlPair>();
#include "etl/private/diagnostic_pessimizing-move_push.h"
CHECK_EQUAL(1, selector(std::move(EtlPair(1, "Hello"))));
CHECK_EQUAL(2, selector(std::move(StdPair(2, "Hello"))));
#include "etl/private/diagnostic_pop.h"
}
//*************************************************************************
@ -407,8 +409,11 @@ namespace
StdPair sp2(2, "World");
auto selector = etl::select2nd<EtlPair>();
#include "etl/private/diagnostic_pessimizing-move_push.h"
CHECK_EQUAL(std::string("Hello"), selector(std::move(EtlPair(1, "Hello"))));
CHECK_EQUAL(std::string("World"), selector(std::move(StdPair(1, "World"))));
#include "etl/private/diagnostic_pop.h"
}
//*************************************************************************

View File

@ -634,29 +634,6 @@ namespace
CHECK(is_equal);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_back_insert_iterator)
{
Data data={0,1,2,3,4,5,6,7,8,9};
Data expected={0,1,4,9,16,25,36,49,64,81};
Data transformed;
auto squared = [](int value){
return value*value;
};
etl::transform(data.cbegin(),data.cend(),etl::back_inserter(transformed),squared);
CHECK_EQUAL(expected.size(), transformed.size());
bool transformed_equals_expected = std::equal(transformed.begin(),
transformed.end(),
expected.begin());
CHECK(transformed_equals_expected);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_back)
{