mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-29 02:17:09 +08:00
* Fixed make_array rejecting const-qualified lvalues of the element type make_array forwarded each argument as T (the element type) rather than as its own deduced type. etl::forward<T> accepts only a non-const T& or a T&&, and a T&& cannot bind to a reference-related const lvalue, so any call passing a const-qualified lvalue of type T failed to compile: static const char c = 42; etl::make_array<char>(c, c); // error: would lose const qualifier Arguments of *other* types slipped through via temporary materialisation, which is why the existing conversion and move tests never caught it. Forward each argument as its own deduced type and convert explicitly with static_cast<T>. The explicit conversion is required rather than plain forwarding: function parameters are not constant expressions, so narrowing initialisers such as make_array<char>(0, 1) - which the old code accepted and the tests cover - would otherwise be rejected by the braced initialiser list. Adds regression tests for const/non-const lvalues of the element type and for constexpr evaluation. Verified with clang 22 (C++14/17/20) and GCC 14 (C++11/20); existing conversion and move-only patterns still compile. * Fixed make_deque rejecting const-qualified lvalues of the element type make_deque had the same defect fixed for make_array in the previous commit: it forwarded each argument as T (the element type) rather than as its own deduced type. etl::forward<T> accepts only a non-const T& or a T&&, and a T&& cannot bind to a reference-related const lvalue, so any call passing a const-qualified lvalue of type T failed to compile: static const char c = 42; etl::make_deque<char>(c, c); // error: would lose const qualifier An audit of all other make_xxx container factories found no further instances - they forward each argument as its own deduced pack type, which is the correct idiom. Forward each argument as its own deduced type and convert explicitly with static_cast<T>. The explicit conversion keeps narrowing initialisers such as make_deque<char>(0, 1) - which the old code accepted and test_make_deque covers - working, which plain forwarding into the braced initialiser list would reject. Adds a regression test for const/non-const lvalues of the element type. No constexpr test, unlike make_array: etl::deque is not a literal type, so make_deque cannot be evaluated at compile time. Verified with clang 22 (C++14/17/20); the new test fails to compile before the fix and passes after, and all 101 deque tests pass. * Added narrowing-conversion regression tests for make_array and make_deque Review feedback on the make_deque fix: the const-lvalue regression test only passes arguments that already have the element type, so nothing exercises the static_cast<T> conversion that keeps narrowing initialisers working. If the implementation regressed to plain forwarding into the braced initialiser list, narrowing calls such as make_deque<char>(0, 1) would fail to compile. make_array already covered narrowing from int literals via test_make_array, but neither container covered conversion from const-qualified lvalues of a different type (const int narrowed to char), which combines both dimensions of the fix. Adds a matching test to each container covering int literals plus const/non-const int lvalues, all narrowed to char. Verified with clang 22 (C++17): 102 deque and 53 array tests pass. * Added const-lvalue regression tests for the remaining make_xxx factories Review feedback on the make_array/make_deque fixes asked whether the same defect - rejecting const-qualified lvalue arguments by forwarding each argument as the element type rather than as its own deduced type - exists in the other make_xxx container factories. The audit found that it does not: the other factories forward each argument as its own deduced pack type. These tests pin that down explicitly for every remaining factory, mirroring the make_array and make_deque regression tests: - make_vector, make_forward_list, make_indirect_vector (element type deduced via common_type): const/non-const char lvalues, element type checked. - make_set, make_multiset, make_flat_set, make_flat_multiset, make_unordered_set, make_unordered_multiset: const/non-const lvalues of the key type. - make_map, make_multimap, make_flat_map, make_flat_multimap, make_unordered_map, make_unordered_multimap: const/non-const lvalues of the pair type. make_reference_flat_* are excluded: they cannot currently be instantiated at all (no initializer_list constructor exists in the reference containers), which is reported separately. Verified with clang 22 (C++17): all 15 test suites pass (996 tests). * Added make_forward_list parity tests matching the make_list fixes Checked whether the make_list defect - taking its argument pack by value, costing an extra move per lvalue argument - also applies to make_forward_list. It does not: make_forward_list already takes its pack by forwarding reference, as make_vector does. No header change is needed. Adds the two tests that accompanied the make_list fix so that forward_list has the same coverage and the same regression detector: - test_make_forward_list_common_type_from_mixed_types, confirming the element type deduction through common_type. - test_make_forward_list_argument_copy_and_move_counts, an instrumented type counting copy/move constructions. This is the test that fails if the pack ever regresses to by-value (one extra move per lvalue argument). The exact move counts are C++17-only, as before C++17 the non-guaranteed return elision may add a move per element. Verified with clang 22 (C++17): all 67 forward_list tests pass. --------- Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
1649 lines
55 KiB
C++
1649 lines
55 KiB
C++
///******************************************************************************
|
|
// The MIT License(MIT)
|
|
//
|
|
// Embedded Template Library.
|
|
// https://github.com/ETLCPP/etl
|
|
// https://www.etlcpp.com
|
|
//
|
|
// Copyright(c) 2019 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.
|
|
//******************************************************************************/
|
|
|
|
#include "unit_test_framework.h"
|
|
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "data.h"
|
|
#include "etl/indirect_vector.h"
|
|
|
|
namespace
|
|
{
|
|
SUITE(test_indirect_vector)
|
|
{
|
|
static const size_t SIZE = 12UL;
|
|
|
|
typedef TestDataNDC<std::string> NDC;
|
|
typedef TestDataDC<std::string> DC;
|
|
|
|
static NDC ndc("NDC");
|
|
|
|
typedef etl::indirect_vector<NDC, SIZE> DataNDC;
|
|
typedef etl::iindirect_vector<NDC> IDataNDC;
|
|
typedef std::vector<NDC> CompareDataNDC;
|
|
|
|
typedef etl::indirect_vector<DC, SIZE> DataDC;
|
|
typedef etl::iindirect_vector<DC> IDataDC;
|
|
typedef std::vector<DC> CompareDataDC;
|
|
|
|
CompareDataNDC initial_data;
|
|
CompareDataNDC less_data;
|
|
CompareDataNDC greater_data;
|
|
CompareDataNDC shorter_data;
|
|
CompareDataNDC different_data;
|
|
CompareDataNDC insert_data;
|
|
CompareDataNDC ordered_data;
|
|
CompareDataNDC part_ordered_data;
|
|
CompareDataNDC part_reverse_ordered_data;
|
|
CompareDataNDC stable_default_ordered_data;
|
|
CompareDataNDC stable_reverse_ordered_data;
|
|
CompareDataNDC stable_greater_ordered_data;
|
|
CompareDataNDC stable_greater_reverse_ordered_data;
|
|
CompareDataNDC unordered_data;
|
|
CompareDataNDC stable_part_ordered_data;
|
|
CompareDataNDC stable_part_greater_ordered_data;
|
|
CompareDataNDC blank_data;
|
|
|
|
template <typename TIterator, typename TFunctor>
|
|
void test_algorithm(TIterator first1, TIterator last1, TIterator first2, TFunctor functor)
|
|
{
|
|
while (first1 != last1)
|
|
{
|
|
functor(*first1++, *first2++);
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
struct SetupFixture
|
|
{
|
|
SetupFixture()
|
|
{
|
|
NDC n[] = {NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("4"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9")};
|
|
NDC n_insert[] = {NDC("11"), NDC("12"), NDC("13")};
|
|
NDC n_less[] = {NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("4"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9")};
|
|
NDC n_greater[] = {NDC("0"), NDC("1"), NDC("2"), NDC("4"), NDC("4"), NDC("4"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9")};
|
|
|
|
NDC n_unordered[] = {NDC("1"), NDC("4", 1), NDC("7"), NDC("4", 2), NDC("2"), NDC("4", 3),
|
|
NDC("3"), NDC("6"), NDC("9"), NDC("0"), NDC("8"), NDC("5")};
|
|
|
|
NDC n_ordered[] = {NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("4"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9")};
|
|
NDC n_stable_default_ordered[] = {NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4", 1), NDC("4", 2),
|
|
NDC("4", 3), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9")};
|
|
NDC n_stable_reverse_ordered[] = {NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4", 3), NDC("4", 2),
|
|
NDC("4", 1), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9")};
|
|
NDC n_stable_greater_ordered[] = {NDC("9"), NDC("8"), NDC("7"), NDC("6"), NDC("5"), NDC("4", 1),
|
|
NDC("4", 2), NDC("4", 3), NDC("3"), NDC("2"), NDC("1"), NDC("0")};
|
|
NDC n_stable_greater_reverse_ordered_data[] = {NDC("9"), NDC("8"), NDC("7"), NDC("6"), NDC("5"), NDC("4", 3),
|
|
NDC("4", 2), NDC("4", 1), NDC("3"), NDC("2"), NDC("1"), NDC("0")};
|
|
|
|
NDC n_part_ordered[] = {NDC("1"), NDC("4", 1), NDC("0"), NDC("2"), NDC("3"), NDC("4"),
|
|
NDC("4"), NDC("6"), NDC("7"), NDC("9"), NDC("8"), NDC("5")};
|
|
NDC n_part_reverse_ordered[] = {NDC("1"), NDC("4"), NDC("9"), NDC("7"), NDC("6"), NDC("4"),
|
|
NDC("4"), NDC("3"), NDC("2"), NDC("0"), NDC("8"), NDC("5")};
|
|
|
|
NDC n_stable_part_ordered[] = {NDC("1"), NDC("4", 1), NDC("0"), NDC("2"), NDC("3"), NDC("4", 2),
|
|
NDC("4", 3), NDC("6"), NDC("7"), NDC("9"), NDC("8"), NDC("5")};
|
|
NDC n_stable_part_greater_ordered[] = {NDC("1"), NDC("4", 1), NDC("9"), NDC("7"), NDC("6"), NDC("4", 2),
|
|
NDC("4", 3), NDC("3"), NDC("2"), NDC("0"), NDC("8"), NDC("5")};
|
|
|
|
NDC n_blank[] = {NDC("99"), NDC("99"), NDC("99"), NDC("99"), NDC("99"), NDC("99"),
|
|
NDC("99"), NDC("99"), NDC("99"), NDC("99"), NDC("99"), NDC("99")};
|
|
|
|
initial_data.assign(std::begin(n), std::end(n));
|
|
insert_data.assign(std::begin(n_insert), std::end(n_insert));
|
|
less_data.assign(std::begin(n_less), std::end(n_less));
|
|
greater_data.assign(std::begin(n_greater), std::end(n_greater));
|
|
shorter_data.assign(std::begin(n_greater), std::end(n_greater) - 1);
|
|
different_data.assign(initial_data.rbegin(), initial_data.rend());
|
|
ordered_data.assign(std::begin(n_ordered), std::end(n_ordered));
|
|
part_ordered_data.assign(std::begin(n_part_ordered), std::end(n_part_ordered));
|
|
part_reverse_ordered_data.assign(std::begin(n_part_reverse_ordered), std::end(n_part_reverse_ordered));
|
|
unordered_data.assign(std::begin(n_unordered), std::end(n_unordered));
|
|
stable_default_ordered_data.assign(std::begin(n_stable_default_ordered), std::end(n_stable_default_ordered));
|
|
stable_reverse_ordered_data.assign(std::begin(n_stable_reverse_ordered), std::end(n_stable_reverse_ordered));
|
|
stable_greater_ordered_data.assign(std::begin(n_stable_greater_ordered), std::end(n_stable_greater_ordered));
|
|
stable_greater_reverse_ordered_data.assign(std::begin(n_stable_greater_reverse_ordered_data),
|
|
std::end(n_stable_greater_reverse_ordered_data));
|
|
stable_part_ordered_data.assign(std::begin(n_stable_part_ordered), std::end(n_stable_part_ordered));
|
|
stable_part_greater_ordered_data.assign(std::begin(n_stable_part_greater_ordered), std::end(n_stable_part_greater_ordered));
|
|
blank_data.assign(std::begin(n_blank), std::end(n_blank));
|
|
}
|
|
};
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_default_constructor)
|
|
{
|
|
DataDC data;
|
|
|
|
CHECK_EQUAL(data.size(), size_t(0));
|
|
CHECK(data.empty());
|
|
CHECK_EQUAL(data.capacity(), SIZE);
|
|
CHECK_EQUAL(data.max_size(), SIZE);
|
|
}
|
|
|
|
#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
|
//*************************************************************************
|
|
TEST(test_cpp17_deduced_constructor)
|
|
{
|
|
etl::indirect_vector data{NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9")};
|
|
etl::indirect_vector<NDC, 10U> check = {NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9")};
|
|
|
|
CHECK(!data.empty());
|
|
CHECK(data.full());
|
|
CHECK(data.begin() != data.end());
|
|
CHECK_EQUAL(10U, data.size());
|
|
CHECK_EQUAL(0U, data.available());
|
|
CHECK_EQUAL(10U, data.capacity());
|
|
CHECK_EQUAL(10U, data.max_size());
|
|
CHECK(data == check);
|
|
}
|
|
#endif
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_destruct_via_ivector)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
const NDC INITIAL_VALUE("1");
|
|
|
|
int current_count = NDC::get_instance_count();
|
|
|
|
DataNDC* p = new DataNDC(INITIAL_SIZE, INITIAL_VALUE);
|
|
delete p;
|
|
|
|
DataNDC* pdata = new DataNDC(INITIAL_SIZE, INITIAL_VALUE);
|
|
CHECK_EQUAL(int(current_count + int(INITIAL_SIZE)), NDC::get_instance_count());
|
|
|
|
IDataNDC* pidata = pdata;
|
|
delete pidata;
|
|
CHECK_EQUAL(current_count, NDC::get_instance_count());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_iterator_comparison_empty)
|
|
{
|
|
DataDC data;
|
|
|
|
CHECK(data.begin() == data.end());
|
|
CHECK(data.cbegin() == data.cend());
|
|
CHECK(data.rbegin() == data.rend());
|
|
CHECK(data.crbegin() == data.crend());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_constructor_size)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
DataDC data(INITIAL_SIZE);
|
|
|
|
CHECK(data.size() == INITIAL_SIZE);
|
|
CHECK(!data.empty());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_constructor_size_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
const NDC INITIAL_VALUE("1");
|
|
|
|
std::vector<NDC> compare_data(INITIAL_SIZE, INITIAL_VALUE);
|
|
DataNDC data(size_t(5), NDC("1"));
|
|
|
|
CHECK(data.size() == INITIAL_SIZE);
|
|
CHECK(!data.empty());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_constructor_size_excess)
|
|
{
|
|
CHECK_THROW(DataDC data(SIZE + 1), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_constructor_range)
|
|
{
|
|
CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
DataNDC data(compare_data.begin(), compare_data.end());
|
|
|
|
CHECK(data.size() == SIZE);
|
|
CHECK(!data.empty());
|
|
}
|
|
|
|
#if ETL_HAS_INITIALIZER_LIST
|
|
//*************************************************************************
|
|
TEST(test_constructor_initializer_list)
|
|
{
|
|
CompareDataNDC compare_data = {NDC("0"), NDC("1"), NDC("2"), NDC("3")};
|
|
DataNDC data = {NDC("0"), NDC("1"), NDC("2"), NDC("3")};
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
|
|
}
|
|
#endif
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_copy_constructor)
|
|
{
|
|
DataNDC data(initial_data.begin(), initial_data.end());
|
|
DataNDC data2(data);
|
|
CHECK(data2 == data);
|
|
|
|
data2[2] = NDC("X");
|
|
CHECK(data2 != data);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_move_constructor)
|
|
{
|
|
typedef etl::indirect_vector<std::unique_ptr<uint32_t>, SIZE> Data;
|
|
|
|
std::unique_ptr<uint32_t> p1(new uint32_t(1U));
|
|
std::unique_ptr<uint32_t> p2(new uint32_t(2U));
|
|
std::unique_ptr<uint32_t> p3(new uint32_t(3U));
|
|
std::unique_ptr<uint32_t> p4(new uint32_t(4U));
|
|
|
|
Data data1;
|
|
data1.push_back(std::move(p1));
|
|
data1.push_back(std::move(p2));
|
|
data1.push_back(std::move(p3));
|
|
data1.push_back(std::move(p4));
|
|
|
|
CHECK(!bool(p1));
|
|
CHECK(!bool(p2));
|
|
CHECK(!bool(p3));
|
|
CHECK(!bool(p4));
|
|
|
|
Data data2(std::move(data1));
|
|
|
|
CHECK_EQUAL(0U, data1.size());
|
|
CHECK_EQUAL(4U, data2.size());
|
|
|
|
CHECK_EQUAL(1U, *data2[0]);
|
|
CHECK_EQUAL(2U, *data2[1]);
|
|
CHECK_EQUAL(3U, *data2[2]);
|
|
CHECK_EQUAL(4U, *data2[3]);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_assignment)
|
|
{
|
|
DataNDC data(initial_data.begin(), initial_data.end());
|
|
DataNDC other_data;
|
|
|
|
other_data = data;
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), other_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_move_assignment)
|
|
{
|
|
typedef etl::indirect_vector<std::unique_ptr<uint32_t>, SIZE> Data;
|
|
|
|
std::unique_ptr<uint32_t> p1(new uint32_t(1U));
|
|
std::unique_ptr<uint32_t> p2(new uint32_t(2U));
|
|
std::unique_ptr<uint32_t> p3(new uint32_t(3U));
|
|
std::unique_ptr<uint32_t> p4(new uint32_t(4U));
|
|
std::unique_ptr<uint32_t> p5(new uint32_t(5U));
|
|
|
|
Data data1;
|
|
data1.push_back(std::move(p1));
|
|
data1.push_back(std::move(p2));
|
|
data1.push_back(std::move(p3));
|
|
data1.push_back(std::move(p4));
|
|
|
|
CHECK(!bool(p1));
|
|
CHECK(!bool(p2));
|
|
CHECK(!bool(p3));
|
|
CHECK(!bool(p4));
|
|
|
|
Data data2;
|
|
data2.push_back(std::move(p5));
|
|
data2 = std::move(data1);
|
|
|
|
CHECK_EQUAL(0U, data1.size());
|
|
CHECK_EQUAL(4U, data2.size());
|
|
|
|
CHECK_EQUAL(1U, *data2[0]);
|
|
CHECK_EQUAL(2U, *data2[1]);
|
|
CHECK_EQUAL(3U, *data2[2]);
|
|
CHECK_EQUAL(4U, *data2[3]);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_assignment_iterface)
|
|
{
|
|
DataNDC data1(initial_data.begin(), initial_data.end());
|
|
DataNDC data2;
|
|
|
|
IDataNDC& idata1 = data1;
|
|
IDataNDC& idata2 = data2;
|
|
|
|
idata2 = idata1;
|
|
|
|
bool is_equal = std::equal(data1.begin(), data1.end(), data2.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_move_assignment_interface)
|
|
{
|
|
typedef etl::indirect_vector<std::unique_ptr<uint32_t>, SIZE> Data;
|
|
typedef etl::iindirect_vector<std::unique_ptr<uint32_t>> IData;
|
|
|
|
std::unique_ptr<uint32_t> p1(new uint32_t(1U));
|
|
std::unique_ptr<uint32_t> p2(new uint32_t(2U));
|
|
std::unique_ptr<uint32_t> p3(new uint32_t(3U));
|
|
std::unique_ptr<uint32_t> p4(new uint32_t(4U));
|
|
|
|
Data data1;
|
|
data1.push_back(std::move(p1));
|
|
data1.push_back(std::move(p2));
|
|
data1.push_back(std::move(p3));
|
|
data1.push_back(std::move(p4));
|
|
|
|
Data data2;
|
|
|
|
IData& idata1 = data1;
|
|
IData& idata2 = data2;
|
|
|
|
idata2 = std::move(idata1);
|
|
|
|
CHECK_EQUAL(0U, data1.size());
|
|
CHECK_EQUAL(4U, data2.size());
|
|
|
|
CHECK_EQUAL(1U, *data2[0]);
|
|
CHECK_EQUAL(2U, *data2[1]);
|
|
CHECK_EQUAL(3U, *data2[2]);
|
|
CHECK_EQUAL(4U, *data2[3]);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_self_assignment)
|
|
{
|
|
DataNDC data(initial_data.begin(), initial_data.end());
|
|
DataNDC other_data(data);
|
|
|
|
#include "etl/private/diagnostic_self_assign_overloaded_push.h"
|
|
other_data = other_data;
|
|
#include "etl/private/diagnostic_pop.h"
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), other_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_begin)
|
|
{
|
|
DataDC data(10);
|
|
const DataDC constData(10);
|
|
|
|
CHECK_EQUAL(&data[0], &(*data.begin()));
|
|
CHECK_EQUAL(&data[0], &(*data.cbegin()));
|
|
CHECK_EQUAL(&constData[0], &(*constData.begin()));
|
|
CHECK_EQUAL(&constData[0], &(*constData.cbegin()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_end)
|
|
{
|
|
DataDC data(10U);
|
|
const DataDC constData(10U);
|
|
|
|
CHECK(std::distance(data.begin(), data.end()) == 10U);
|
|
CHECK(std::distance(data.cbegin(), data.cend()) == 10U);
|
|
CHECK(std::distance(constData.begin(), constData.end()) == 10U);
|
|
CHECK(std::distance(constData.cbegin(), constData.cend()) == 10U);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_resize_up)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
const size_t NEW_SIZE = 8UL;
|
|
|
|
DataDC data(INITIAL_SIZE);
|
|
data.resize(NEW_SIZE);
|
|
|
|
CHECK_EQUAL(data.size(), NEW_SIZE);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_resize_up_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
const size_t NEW_SIZE = 8UL;
|
|
const NDC INITIAL_VALUE("1");
|
|
|
|
DataNDC data(INITIAL_SIZE, INITIAL_VALUE);
|
|
data.resize(NEW_SIZE, INITIAL_VALUE);
|
|
|
|
std::vector<NDC> compare_data(NEW_SIZE, INITIAL_VALUE);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_resize_excess)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
const size_t NEW_SIZE = SIZE + 1UL;
|
|
|
|
DataDC data(INITIAL_SIZE);
|
|
|
|
CHECK_THROW(data.resize(NEW_SIZE), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_resize_down)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
const size_t NEW_SIZE = 2UL;
|
|
|
|
DataDC data(INITIAL_SIZE);
|
|
data.resize(NEW_SIZE);
|
|
|
|
CHECK_EQUAL(data.size(), NEW_SIZE);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_resize_down_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
const size_t NEW_SIZE = 2UL;
|
|
const NDC INITIAL_VALUE("1");
|
|
|
|
DataNDC data(INITIAL_SIZE, INITIAL_VALUE);
|
|
data.resize(NEW_SIZE, INITIAL_VALUE);
|
|
|
|
CHECK_EQUAL(data.size(), NEW_SIZE);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_reserve)
|
|
{
|
|
DataNDC data;
|
|
|
|
CHECK_NO_THROW(data.reserve(data.max_size()));
|
|
CHECK_THROW(data.reserve(data.max_size() + 1), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_empty)
|
|
{
|
|
DataDC data;
|
|
data.resize(data.max_size());
|
|
|
|
CHECK(data.full());
|
|
CHECK(!data.empty());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_full)
|
|
{
|
|
DataNDC data;
|
|
|
|
CHECK(!data.full());
|
|
CHECK(data.empty());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_index)
|
|
{
|
|
CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
DataNDC data(compare_data.begin(), compare_data.end());
|
|
|
|
for (size_t i = 0UL; i < data.size(); ++i)
|
|
{
|
|
CHECK_EQUAL(data[i], compare_data[i]);
|
|
}
|
|
|
|
CHECK_THROW(data[data.size()], etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_index_const)
|
|
{
|
|
const CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
const DataNDC data(compare_data.begin(), compare_data.end());
|
|
|
|
for (size_t i = 0UL; i < data.size(); ++i)
|
|
{
|
|
CHECK_EQUAL(data[i], compare_data[i]);
|
|
}
|
|
|
|
CHECK_THROW(data[data.size()], etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_at)
|
|
{
|
|
CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
DataNDC data(initial_data.begin(), initial_data.end());
|
|
|
|
for (size_t i = 0UL; i < data.size(); ++i)
|
|
{
|
|
CHECK_EQUAL(data.at(i), compare_data.at(i));
|
|
}
|
|
|
|
CHECK_THROW(data.at(data.size()), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_at_const)
|
|
{
|
|
const CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
const DataNDC data(initial_data.begin(), initial_data.end());
|
|
|
|
for (size_t i = 0UL; i < data.size(); ++i)
|
|
{
|
|
CHECK_EQUAL(data.at(i), compare_data.at(i));
|
|
}
|
|
|
|
CHECK_THROW(data.at(data.size()), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_front)
|
|
{
|
|
CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
DataNDC data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.front() == compare_data.front());
|
|
|
|
DataNDC emptyData;
|
|
CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_front_const)
|
|
{
|
|
const CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
const DataNDC data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.front() == compare_data.front());
|
|
|
|
const DataNDC emptyData;
|
|
CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_back)
|
|
{
|
|
CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
DataNDC data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.back() == compare_data.back());
|
|
|
|
DataNDC emptyData;
|
|
CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_back_const)
|
|
{
|
|
const CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
const DataNDC data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.back() == compare_data.back());
|
|
|
|
const DataNDC emptyData;
|
|
CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_assign_range)
|
|
{
|
|
CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
DataNDC data;
|
|
|
|
data.assign(compare_data.begin(), compare_data.end());
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_assign_size_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
const NDC INITIAL_VALUE("1");
|
|
std::vector<NDC> compare_data(INITIAL_SIZE, INITIAL_VALUE);
|
|
|
|
DataNDC data;
|
|
data.assign(INITIAL_SIZE, INITIAL_VALUE);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_assign_size_value_excess)
|
|
{
|
|
const size_t INITIAL_SIZE = SIZE;
|
|
const size_t EXCESS_SIZE = SIZE + 1UL;
|
|
const NDC INITIAL_VALUE("1");
|
|
std::vector<NDC> compare_data(INITIAL_SIZE, INITIAL_VALUE);
|
|
|
|
DataNDC data;
|
|
|
|
CHECK_THROW(data.assign(EXCESS_SIZE, INITIAL_VALUE), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_push_back)
|
|
{
|
|
CompareDataNDC compare_data;
|
|
DataNDC data;
|
|
|
|
for (size_t i = 0UL; i < SIZE; ++i)
|
|
{
|
|
std::string value(" ");
|
|
value[0] = char('A' + i);
|
|
compare_data.push_back(NDC(value));
|
|
data.push_back(NDC(value));
|
|
}
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_push_back_excess)
|
|
{
|
|
DataNDC data;
|
|
|
|
for (size_t i = 0UL; i < SIZE; ++i)
|
|
{
|
|
std::string value(" ");
|
|
value[0] = char('A' + i);
|
|
data.push_back(NDC(value));
|
|
}
|
|
|
|
CHECK_THROW(data.push_back(NDC("Z")), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_back_default_value)
|
|
{
|
|
CompareDataDC compare_data;
|
|
DataDC data;
|
|
|
|
for (size_t i = 0UL; i < SIZE; ++i)
|
|
{
|
|
compare_data.emplace_back();
|
|
data.emplace_back();
|
|
}
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_back)
|
|
{
|
|
CompareDataNDC compare_data;
|
|
DataNDC data;
|
|
|
|
for (size_t i = 0UL; i < SIZE; ++i)
|
|
{
|
|
std::string value(" ");
|
|
value[0] = char('A' + i);
|
|
compare_data.emplace_back(value);
|
|
data.emplace_back(value);
|
|
}
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_back_return)
|
|
{
|
|
DataNDC data;
|
|
std::string value1("A");
|
|
std::string value2("B");
|
|
|
|
data.emplace_back(value1);
|
|
auto& back = data.emplace_back(value2);
|
|
CHECK_EQUAL(back, data.back());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_back_excess)
|
|
{
|
|
DataNDC data;
|
|
|
|
for (size_t i = 0UL; i < SIZE; ++i)
|
|
{
|
|
std::string value(" ");
|
|
value[0] = char('A' + i);
|
|
data.emplace_back(value);
|
|
}
|
|
|
|
CHECK_THROW(data.emplace_back("Z"), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_push_back_unique_ptr)
|
|
{
|
|
etl::indirect_vector<std::unique_ptr<int>, SIZE> data;
|
|
|
|
std::unique_ptr<int> p1(new int(1));
|
|
std::unique_ptr<int> p2(new int(2));
|
|
std::unique_ptr<int> p3(new int(3));
|
|
std::unique_ptr<int> p4(new int(4));
|
|
|
|
data.push_back(std::move(p1));
|
|
data.push_back(std::move(p2));
|
|
data.push_back(std::move(p3));
|
|
data.push_back(std::move(p4));
|
|
|
|
CHECK(!bool(p1));
|
|
CHECK(!bool(p2));
|
|
CHECK(!bool(p3));
|
|
CHECK(!bool(p4));
|
|
|
|
CHECK_EQUAL(1, *data[0]);
|
|
CHECK_EQUAL(2, *data[1]);
|
|
CHECK_EQUAL(3, *data[2]);
|
|
CHECK_EQUAL(4, *data[3]);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_int)
|
|
{
|
|
etl::indirect_vector<int, SIZE> data;
|
|
|
|
int p1(1);
|
|
int p2(2);
|
|
int p3(3);
|
|
int p4(4);
|
|
|
|
data.insert(data.begin(), p1);
|
|
data.insert(data.begin(), p2);
|
|
data.insert(data.begin(), p3);
|
|
data.insert(data.begin(), p4);
|
|
|
|
CHECK_EQUAL(4, data[0]);
|
|
CHECK_EQUAL(3, data[1]);
|
|
CHECK_EQUAL(2, data[2]);
|
|
CHECK_EQUAL(1, data[3]);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_unique_ptr)
|
|
{
|
|
etl::indirect_vector<std::unique_ptr<int>, SIZE> data;
|
|
|
|
std::unique_ptr<int> p1(new int(1));
|
|
std::unique_ptr<int> p2(new int(2));
|
|
std::unique_ptr<int> p3(new int(3));
|
|
std::unique_ptr<int> p4(new int(4));
|
|
|
|
data.insert(data.begin(), std::move(p1));
|
|
data.insert(data.begin(), std::move(p2));
|
|
data.insert(data.begin(), std::move(p3));
|
|
data.insert(data.begin(), std::move(p4));
|
|
|
|
CHECK(!bool(p1));
|
|
CHECK(!bool(p2));
|
|
CHECK(!bool(p3));
|
|
CHECK(!bool(p4));
|
|
|
|
CHECK_EQUAL(1, *data[3]);
|
|
CHECK_EQUAL(4, *data[0]);
|
|
CHECK_EQUAL(3, *data[1]);
|
|
CHECK_EQUAL(2, *data[2]);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_back_multiple)
|
|
{
|
|
class Data
|
|
{
|
|
public:
|
|
|
|
std::string a;
|
|
size_t b;
|
|
double c;
|
|
const char* d;
|
|
Data(std::string w)
|
|
: a(w)
|
|
, b(0)
|
|
, c(0.0)
|
|
, d(0)
|
|
{
|
|
}
|
|
Data(std::string w, size_t x)
|
|
: a(w)
|
|
, b(x)
|
|
, c(0.0)
|
|
, d(0)
|
|
{
|
|
}
|
|
Data(std::string w, size_t x, double y)
|
|
: a(w)
|
|
, b(x)
|
|
, c(y)
|
|
, d(0)
|
|
{
|
|
}
|
|
Data(std::string w, size_t x, double y, const char* z)
|
|
: a(w)
|
|
, b(x)
|
|
, c(y)
|
|
, d(z)
|
|
{
|
|
}
|
|
bool operator==(const Data& other) const
|
|
{
|
|
return (a == other.a) && (b == other.b) && !(c < other.c) && !(c > other.c) && (d == other.d);
|
|
}
|
|
};
|
|
|
|
std::vector<Data> compare_data;
|
|
etl::indirect_vector<Data, SIZE * 4> data;
|
|
|
|
const char* p = (const char*)0x12345678UL;
|
|
|
|
std::string s;
|
|
for (size_t i = 0UL; i < SIZE; ++i)
|
|
{
|
|
s += "x";
|
|
|
|
// 4 arguments
|
|
compare_data.emplace_back(s, i, static_cast<double>(i) + 0.1234, p);
|
|
data.emplace_back(s, i, static_cast<double>(i) + 0.1234, p);
|
|
|
|
// 3 arguments
|
|
compare_data.emplace_back(s, i, static_cast<double>(i) + 0.1234);
|
|
data.emplace_back(s, i, static_cast<double>(i) + 0.1234);
|
|
|
|
// 2 arguments
|
|
compare_data.emplace_back(s, i);
|
|
data.emplace_back(s, i);
|
|
|
|
// 1 argument
|
|
compare_data.emplace_back(s);
|
|
data.emplace_back(s);
|
|
}
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
const bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
// The C++11 variadic version uses non-const rvalue references so has the
|
|
// ability to emplace non-const reference members, the pre-C++11 const
|
|
// reference overloads does not have the ability to pass const reference
|
|
// parameters to non-const constructor parameters (like the members in Data
|
|
// below) So this is only tested on C++11 onwards
|
|
TEST_FIXTURE(SetupFixture, test_emplace_back_non_const_references)
|
|
{
|
|
#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_VECTOR_FORCE_CPP03_IMPLEMENTATION)
|
|
class Data
|
|
{
|
|
public:
|
|
|
|
std::string& a;
|
|
size_t& b;
|
|
double& c;
|
|
const char* d;
|
|
Data(std::string& w, size_t& x, double& y, const char* z)
|
|
: a(w)
|
|
, b(x)
|
|
, c(y)
|
|
, d(z)
|
|
{
|
|
}
|
|
bool operator==(const Data& other) const
|
|
{
|
|
return (a == other.a) && (b == other.b) && !(c < other.c) && !(c > other.c) && (d == other.d);
|
|
}
|
|
};
|
|
|
|
std::vector<Data> compare_data;
|
|
etl::indirect_vector<Data, SIZE * 3> data;
|
|
|
|
std::string a = "test_test_test";
|
|
size_t b = 9999UL;
|
|
double c = 123.456;
|
|
const char* d = "abcdefghijklmnopqrstuvwxyz";
|
|
for (size_t i = 0UL; i < SIZE; ++i)
|
|
{
|
|
data.emplace_back(a, b, c, d);
|
|
compare_data.emplace_back(a, b, c, d);
|
|
}
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
const bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
#endif
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_pop_back)
|
|
{
|
|
CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
DataNDC data(initial_data.begin(), initial_data.end());
|
|
|
|
compare_data.pop_back();
|
|
compare_data.pop_back();
|
|
|
|
data.pop_back();
|
|
data.pop_back();
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_pop_back_exception)
|
|
{
|
|
DataDC data;
|
|
|
|
data.resize(2);
|
|
|
|
data.pop_back();
|
|
data.pop_back();
|
|
|
|
CHECK_THROW(data.pop_back(), etl::vector_empty);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
const NDC INITIAL_VALUE("1");
|
|
|
|
for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset)
|
|
{
|
|
CompareDataNDC compare_data;
|
|
DataNDC data;
|
|
|
|
data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
|
|
data.insert(data.begin() + static_cast<ptrdiff_t>(offset), INITIAL_VALUE);
|
|
compare_data.insert(compare_data.begin() + static_cast<ptrdiff_t>(offset), INITIAL_VALUE);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const NDC INITIAL_VALUE("1");
|
|
|
|
DataNDC data;
|
|
DataNDC data2;
|
|
data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
CHECK_THROW(data.insert(data2.cbegin(), INITIAL_VALUE), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_position_default_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
|
|
for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset)
|
|
{
|
|
CompareDataDC compare_data;
|
|
DataDC data;
|
|
|
|
DC initial[] = {DC("0"), DC("1"), DC("2"), DC("3"), DC("4"), DC("4"), DC("4"), DC("5"), DC("6"), DC("7"), DC("8"), DC("9")};
|
|
|
|
data.assign(std::begin(initial), std::begin(initial) + INITIAL_SIZE);
|
|
compare_data.assign(std::begin(initial), std::begin(initial) + INITIAL_SIZE);
|
|
|
|
data.emplace(data.begin() + static_cast<ptrdiff_t>(offset));
|
|
compare_data.emplace(compare_data.begin() + static_cast<ptrdiff_t>(offset));
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
CHECK(is_equal);
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_position_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
const std::string INITIAL_VALUE("1");
|
|
|
|
for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset)
|
|
{
|
|
CompareDataNDC compare_data;
|
|
DataNDC data;
|
|
|
|
data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
|
|
data.emplace(data.begin() + static_cast<ptrdiff_t>(offset), INITIAL_VALUE);
|
|
compare_data.emplace(compare_data.begin() + static_cast<ptrdiff_t>(offset), INITIAL_VALUE);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_position_value_outofbounds)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const std::string INITIAL_VALUE("1");
|
|
|
|
DataNDC data;
|
|
DataNDC data2;
|
|
data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
CHECK_THROW(data.emplace(data2.begin(), INITIAL_VALUE), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_value_excess)
|
|
{
|
|
const size_t INITIAL_SIZE = SIZE;
|
|
const NDC INITIAL_VALUE("1");
|
|
const NDC UNINITIALISED_VALUE("Z");
|
|
|
|
DataNDC data(INITIAL_SIZE, INITIAL_VALUE);
|
|
|
|
size_t offset = 2UL;
|
|
|
|
CHECK_THROW(data.insert(data.begin() + static_cast<ptrdiff_t>(offset), INITIAL_VALUE), etl::vector_full);
|
|
|
|
offset = 0;
|
|
|
|
CHECK_THROW(data.insert(data.begin() + static_cast<ptrdiff_t>(offset), INITIAL_VALUE), etl::vector_full);
|
|
|
|
offset = data.size();
|
|
|
|
CHECK_THROW(data.insert(data.begin() + static_cast<ptrdiff_t>(offset), INITIAL_VALUE), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_n_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
const size_t INSERT_SIZE = 3UL;
|
|
const NDC INITIAL_VALUE("1");
|
|
|
|
for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset)
|
|
{
|
|
CompareDataNDC compare_data;
|
|
DataNDC data;
|
|
|
|
data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
data.insert(data.begin() + static_cast<ptrdiff_t>(offset), INSERT_SIZE, INITIAL_VALUE);
|
|
compare_data.insert(compare_data.begin() + static_cast<ptrdiff_t>(offset), INSERT_SIZE, INITIAL_VALUE);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds)
|
|
{
|
|
const NDC INITIAL_VALUE("1");
|
|
|
|
DataNDC data;
|
|
DataNDC data2;
|
|
|
|
CHECK_THROW(data.insert(data2.end(), 1, INITIAL_VALUE), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess)
|
|
{
|
|
const size_t INITIAL_SIZE = SIZE;
|
|
const size_t INSERT_SIZE = 4UL;
|
|
const NDC INITIAL_VALUE("1");
|
|
|
|
DataNDC data(INITIAL_SIZE, INITIAL_VALUE);
|
|
|
|
size_t offset = 0UL;
|
|
|
|
CHECK_THROW(data.insert(data.begin() + static_cast<ptrdiff_t>(offset), INSERT_SIZE, INITIAL_VALUE), etl::vector_full);
|
|
|
|
offset = 2;
|
|
|
|
CHECK_THROW(data.insert(data.begin() + static_cast<ptrdiff_t>(offset), INSERT_SIZE, INITIAL_VALUE), etl::vector_full);
|
|
|
|
offset = 4;
|
|
|
|
CHECK_THROW(data.insert(data.begin() + static_cast<ptrdiff_t>(offset), INSERT_SIZE, INITIAL_VALUE), etl::vector_full);
|
|
|
|
offset = data.size();
|
|
|
|
CHECK_THROW(data.insert(data.begin() + static_cast<ptrdiff_t>(offset), INSERT_SIZE, INITIAL_VALUE), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_range)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
const NDC INITIAL_VALUE("1");
|
|
|
|
for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset)
|
|
{
|
|
CompareDataNDC compare_data;
|
|
DataNDC data;
|
|
|
|
data.resize(SIZE, NDC("Z"));
|
|
|
|
data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
data.insert(data.begin() + static_cast<ptrdiff_t>(offset), insert_data.begin(), insert_data.end());
|
|
compare_data.insert(compare_data.begin() + static_cast<ptrdiff_t>(offset), insert_data.begin(), insert_data.end());
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_range_outofbounds)
|
|
{
|
|
DataNDC data;
|
|
DataNDC data2;
|
|
|
|
CHECK_THROW(data.insert(data2.end(), insert_data.begin(), insert_data.end()), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_range_excess)
|
|
{
|
|
const size_t INITIAL_SIZE = 5UL;
|
|
const NDC INITIAL_VALUE("1");
|
|
|
|
DataNDC data(INITIAL_SIZE, INITIAL_VALUE);
|
|
|
|
size_t offset = 0UL;
|
|
|
|
CHECK_THROW(data.insert(data.begin() + static_cast<ptrdiff_t>(offset), initial_data.begin(), initial_data.end()), etl::vector_full);
|
|
|
|
offset = 2;
|
|
|
|
CHECK_THROW(data.insert(data.begin() + static_cast<ptrdiff_t>(offset), initial_data.begin(), initial_data.end()), etl::vector_full);
|
|
|
|
offset = 4;
|
|
|
|
CHECK_THROW(data.insert(data.begin() + static_cast<ptrdiff_t>(offset), initial_data.begin(), initial_data.end()), etl::vector_full);
|
|
|
|
offset = data.size();
|
|
|
|
CHECK_THROW(data.insert(data.begin() + static_cast<ptrdiff_t>(offset), initial_data.begin(), initial_data.end()), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_single)
|
|
{
|
|
CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
DataNDC data(initial_data.begin(), initial_data.end());
|
|
|
|
compare_data.erase(compare_data.cbegin() + 2);
|
|
|
|
data.erase(data.cbegin() + 2);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_single_outofbounds)
|
|
{
|
|
DataNDC data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK_THROW(data.erase(data.end()), etl::vector_out_of_bounds);
|
|
CHECK_THROW(data.erase(data.cend()), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_range)
|
|
{
|
|
CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
DataNDC data(initial_data.begin(), initial_data.end());
|
|
|
|
compare_data.erase(compare_data.cbegin() + 2, compare_data.cbegin() + 4);
|
|
|
|
data.erase(data.cbegin() + 2, data.cbegin() + 4);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds)
|
|
{
|
|
DataNDC data(initial_data.begin(), initial_data.end());
|
|
DataNDC data2(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK_THROW(data.erase(data2.begin(), data2.end()), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_clear)
|
|
{
|
|
CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
DataNDC data(compare_data.begin(), compare_data.end());
|
|
data.clear();
|
|
|
|
CHECK_EQUAL(data.size(), 0UL);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_iterator)
|
|
{
|
|
CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
DataNDC data(compare_data.begin(), compare_data.end());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_const_iterator)
|
|
{
|
|
CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
DataNDC data(compare_data.begin(), compare_data.end());
|
|
|
|
bool is_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_reverse_iterator)
|
|
{
|
|
CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
DataNDC data(compare_data.begin(), compare_data.end());
|
|
|
|
bool is_equal = std::equal(data.rbegin(), data.rend(), compare_data.rbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_const_reverse_iterator)
|
|
{
|
|
const CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
const DataNDC data(compare_data.begin(), compare_data.end());
|
|
|
|
bool is_equal = std::equal(data.crbegin(), data.crend(), compare_data.crbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_const_reverse_iterator2)
|
|
{
|
|
const CompareDataNDC compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
const DataNDC data(compare_data.begin(), compare_data.end());
|
|
|
|
bool is_equal = std::equal(data.rbegin(), data.rend(), compare_data.rbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_equal)
|
|
{
|
|
const DataNDC initial1(initial_data.begin(), initial_data.end());
|
|
const DataNDC initial2(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(initial1 == initial2);
|
|
|
|
const DataNDC different(different_data.begin(), different_data.end());
|
|
|
|
CHECK(!(initial1 == different));
|
|
|
|
const DataNDC shorter(shorter_data.begin(), shorter_data.end());
|
|
|
|
CHECK(!(shorter == initial1));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_not_equal)
|
|
{
|
|
const DataNDC initial1(initial_data.begin(), initial_data.end());
|
|
const DataNDC initial2(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(!(initial1 != initial2));
|
|
|
|
const DataNDC different(different_data.begin(), different_data.end());
|
|
|
|
CHECK(initial1 != different);
|
|
|
|
const DataNDC shorter(shorter_data.begin(), shorter_data.end());
|
|
|
|
CHECK(shorter != initial1);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_less_than)
|
|
{
|
|
const DataNDC less(less_data.begin(), less_data.end());
|
|
const DataNDC initial(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK((less < initial) == (less_data < initial_data));
|
|
|
|
const DataNDC greater(greater_data.begin(), greater_data.end());
|
|
|
|
CHECK((greater < initial) == (greater_data < initial_data));
|
|
|
|
const DataNDC shorter(shorter_data.begin(), shorter_data.end());
|
|
|
|
CHECK((shorter < initial) == (shorter_data < initial_data));
|
|
CHECK((initial < shorter) == (initial_data < shorter_data));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_less_than_or_equal)
|
|
{
|
|
const DataNDC less(less_data.begin(), less_data.end());
|
|
const DataNDC initial(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK((less <= initial) == (less_data <= initial_data));
|
|
|
|
const DataNDC greater(greater_data.begin(), greater_data.end());
|
|
|
|
CHECK((greater <= initial) == (greater_data <= initial_data));
|
|
|
|
const DataNDC shorter(shorter_data.begin(), shorter_data.end());
|
|
|
|
CHECK((shorter <= initial) == (shorter_data <= initial_data));
|
|
CHECK((initial <= shorter) == (initial_data <= shorter_data));
|
|
|
|
const DataNDC initial2(initial_data.begin(), initial_data.end());
|
|
CHECK((initial <= initial2) == (initial_data <= initial_data));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_greater_than)
|
|
{
|
|
const DataNDC less(less_data.begin(), less_data.end());
|
|
const DataNDC initial(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK((less > initial) == (less_data > initial_data));
|
|
|
|
const DataNDC greater(greater_data.begin(), greater_data.end());
|
|
|
|
CHECK((greater > initial) == (greater_data > initial_data));
|
|
|
|
const DataNDC shorter(shorter_data.begin(), shorter_data.end());
|
|
|
|
CHECK((shorter > initial) == (shorter_data > initial_data));
|
|
CHECK((initial > shorter) == (initial_data > shorter_data));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_greater_than_or_equal)
|
|
{
|
|
const DataNDC less(less_data.begin(), less_data.end());
|
|
const DataNDC initial(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK((less >= initial) == (less_data >= initial_data));
|
|
|
|
const DataNDC greater(greater_data.begin(), greater_data.end());
|
|
|
|
CHECK((greater >= initial) == (greater_data >= initial_data));
|
|
|
|
const DataNDC shorter(shorter_data.begin(), shorter_data.end());
|
|
|
|
CHECK((shorter >= initial) == (shorter_data >= initial_data));
|
|
CHECK((initial >= shorter) == (initial_data > shorter_data));
|
|
|
|
const DataNDC initial2(initial_data.begin(), initial_data.end());
|
|
CHECK((initial >= initial2) == (initial_data >= initial_data));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_indirect_algorithm)
|
|
{
|
|
DataNDC data1(initial_data.begin(), initial_data.end());
|
|
DataNDC data2(initial_data.rbegin(), initial_data.rend());
|
|
|
|
std::reverse(data1.begin().indirection(), data1.end().indirection());
|
|
|
|
bool is_equal = std::equal(data1.begin(), data1.end(), data2.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_indirect_algorithm_void_unary_function)
|
|
{
|
|
struct functor
|
|
{
|
|
void operator()(const NDC& object)
|
|
{
|
|
result += object.value;
|
|
}
|
|
|
|
std::string result;
|
|
};
|
|
|
|
const DataNDC data(ordered_data.begin(), ordered_data.end());
|
|
|
|
typedef typename DataNDC::unary_function_adaptor<functor> wrapped_functor;
|
|
|
|
functor unwrapped;
|
|
wrapped_functor wrapped(unwrapped);
|
|
|
|
functor direct = std::for_each(data.begin(), data.end(), unwrapped);
|
|
|
|
functor indirect = std::for_each(data.begin().indirection(), data.end().indirection(), wrapped).unary_function;
|
|
|
|
CHECK_EQUAL(direct.result, indirect.result);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_indirect_algorithm_bool_unary_function)
|
|
{
|
|
struct functor
|
|
{
|
|
bool operator()(const NDC& object)
|
|
{
|
|
return object.value == "4";
|
|
}
|
|
|
|
std::string result;
|
|
};
|
|
|
|
DataNDC data1(unordered_data.begin(), unordered_data.end());
|
|
DataNDC data2(unordered_data.begin(), unordered_data.end());
|
|
|
|
typedef typename DataNDC::unary_function_adaptor<functor, bool> wrapped_functor;
|
|
|
|
functor unwrapped;
|
|
wrapped_functor wrapped(unwrapped);
|
|
|
|
typename DataNDC::iterator direct = std::partition(data1.begin(), data1.end(), unwrapped);
|
|
|
|
typename DataNDC::indirect_iterator indirect = std::partition(data2.begin().indirection(), data2.end().indirection(), wrapped);
|
|
|
|
bool is_equal = std::equal(data1.begin(), data1.end(), data2.begin());
|
|
|
|
CHECK(is_equal);
|
|
CHECK(*direct == **indirect);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_indirect_algorithm_void_binary_function)
|
|
{
|
|
struct functor
|
|
{
|
|
void operator()(const NDC& lhs, const NDC& rhs)
|
|
{
|
|
result += lhs.value;
|
|
result += rhs.value;
|
|
}
|
|
|
|
std::string result;
|
|
};
|
|
|
|
typedef typename DataNDC::binary_function_adaptor<functor> wrapped_functor;
|
|
|
|
functor unwrapped;
|
|
wrapped_functor wrapped(unwrapped);
|
|
|
|
const DataNDC data1(ordered_data.begin(), ordered_data.end());
|
|
const DataNDC data2(ordered_data.begin(), ordered_data.end());
|
|
|
|
DataNDC direct_data;
|
|
DataNDC indirect_data;
|
|
|
|
test_algorithm(data1.begin(), data1.end(), data2.begin(), unwrapped);
|
|
|
|
test_algorithm(data1.begin().indirection(), data1.end().indirection(), data2.begin().indirection(), wrapped);
|
|
|
|
CHECK_EQUAL(unwrapped.result, wrapped.binary_function.result);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_indirect_algorithm_bool_binary_function)
|
|
{
|
|
DataNDC data(unordered_data.begin(), unordered_data.end());
|
|
|
|
std::sort(data.begin().indirection(), data.end().indirection(),
|
|
typename DataNDC::binary_function_adaptor<std::less<NDC>, bool>(std::less<NDC>()));
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), ordered_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_fill)
|
|
{
|
|
DataNDC data(initial_data.begin(), initial_data.end());
|
|
|
|
data.fill(NDC("99"));
|
|
|
|
CHECK(std::equal(blank_data.begin(), blank_data.end(), data.begin()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
|
|
// Arguments that are const-qualified lvalues must be accepted and must not
|
|
// affect the deduced element type. Guards against the defect fixed for
|
|
// make_array and make_deque, which forwarded each argument as the element
|
|
// type rather than as its own deduced type and so rejected const lvalues.
|
|
TEST(test_make_indirect_vector_from_const_lvalues_of_element_type)
|
|
{
|
|
static const char static_const_lvalue = 42;
|
|
const char local_const_lvalue = 43;
|
|
char mutable_lvalue = 44;
|
|
|
|
auto data = etl::make_indirect_vector(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
|
|
|
using Type = typename std::remove_reference<decltype(data[0])>::type;
|
|
CHECK((std::is_same<char, Type>::value));
|
|
|
|
CHECK_EQUAL(42, data[0]);
|
|
CHECK_EQUAL(43, data[1]);
|
|
CHECK_EQUAL(44, data[2]);
|
|
}
|
|
#endif
|
|
}
|
|
} // namespace
|