diff --git a/ibitset.h b/ibitset.h index 9994e716..7d9112a6 100644 --- a/ibitset.h +++ b/ibitset.h @@ -37,6 +37,7 @@ SOFTWARE. #include "exception.h" #include "integral_limits.h" #include "binary.h" +#include "algorithm.h" #if WIN32 #undef min @@ -595,6 +596,19 @@ namespace etl return *this; } + //************************************************************************* + /// operator = + //************************************************************************* + ibitset& operator =(const ibitset& other) + { + if (this != &other) + { + etl::copy_n(other.pdata, SIZE, pdata); + } + + return *this; + } + //************************************************************************* /// swap //************************************************************************* @@ -679,6 +693,9 @@ namespace etl private: + // Disable copy construction. + ibitset(const ibitset&); + const size_t NBITS; const size_t SIZE; element_t* pdata; diff --git a/ideque.h b/ideque.h index aa769937..aafd32b9 100644 --- a/ideque.h +++ b/ideque.h @@ -459,16 +459,6 @@ namespace etl typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - //************************************************************************* - /// Assignment operator. - //************************************************************************* - ideque& operator =(const ideque& other) - { - assign(other.begin(), other.end()); - - return *this; - } - //************************************************************************* /// Assigns a range to the deque. //************************************************************************* @@ -1215,6 +1205,19 @@ namespace etl return distance(lhs.base(), rhs.base()); } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + ideque& operator =(const ideque& rhs) + { + if (&rhs != this) + { + assign(rhs.begin(), rhs.end()); + } + + return *this; + } + protected: //************************************************************************* @@ -1373,6 +1376,9 @@ namespace etl return index - reference_index; } } + + // Disable copy construction. + ideque(const ideque&); }; } diff --git a/iflat_map.h b/iflat_map.h index bb21571c..34d3e790 100644 --- a/iflat_map.h +++ b/iflat_map.h @@ -492,6 +492,19 @@ namespace etl return std::make_pair(i_lower, std::upper_bound(i_lower, cend(), key, compare())); } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + iflat_map& operator = (const iflat_map& rhs) + { + if (&rhs != this) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + protected: //********************************************************************* @@ -505,6 +518,9 @@ namespace etl private: + // Disable copy construction. + iflat_map(const iflat_map&); + buffer_t& buffer; }; diff --git a/iflat_multimap.h b/iflat_multimap.h index 7c28be2f..a6f4e08a 100644 --- a/iflat_multimap.h +++ b/iflat_multimap.h @@ -439,6 +439,19 @@ namespace etl return std::make_pair(i_lower, std::upper_bound(i_lower, cend(), key, compare())); } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + iflat_multimap& operator = (const iflat_multimap& rhs) + { + if (&rhs != this) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + protected: //********************************************************************* @@ -452,6 +465,9 @@ namespace etl private: + // Disable copy construction. + iflat_multimap(const iflat_multimap&); + buffer_t& buffer; }; diff --git a/iflat_multiset.h b/iflat_multiset.h index 17776e06..8e178c53 100644 --- a/iflat_multiset.h +++ b/iflat_multiset.h @@ -412,6 +412,19 @@ namespace etl return std::equal_range(cbegin(), cend(), key, TKeyCompare()); } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + iflat_multiset& operator = (const iflat_multiset& rhs) + { + if (&rhs != this) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + protected: //********************************************************************* @@ -425,6 +438,9 @@ namespace etl private: + // Disable copy construction. + iflat_multiset(const iflat_multiset&); + buffer_t& buffer; }; diff --git a/iflat_set.h b/iflat_set.h index d31137d3..81f70dbe 100644 --- a/iflat_set.h +++ b/iflat_set.h @@ -417,6 +417,19 @@ namespace etl return std::upper_bound(cbegin(), cend(), key, TKeyCompare()); } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + iflat_set& operator = (const iflat_set& rhs) + { + if (&rhs != this) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + protected: //********************************************************************* @@ -430,6 +443,9 @@ namespace etl private: + // Disable copy construction. + iflat_set(const iflat_set&); + buffer_t& buffer; }; diff --git a/iforward_list.h b/iforward_list.h index f1007dc4..8915bdad 100644 --- a/iforward_list.h +++ b/iforward_list.h @@ -320,16 +320,6 @@ namespace etl return const_iterator(); } - //************************************************************************* - /// Assignment operator. - //************************************************************************* - iforward_list& operator = (const iforward_list& rhs) - { - assign(rhs.cbegin(), rhs.cend()); - - return *this; - } - //************************************************************************* /// Clears the forward_list. //************************************************************************* @@ -795,6 +785,19 @@ namespace etl } } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + iforward_list& operator = (const iforward_list& rhs) + { + if (&rhs != this) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + protected: //************************************************************************* @@ -893,6 +896,9 @@ namespace etl { p_node_pool->release(node); } + + // Disable copy construction. + iforward_list(const iforward_list&); }; } diff --git a/ilist.h b/ilist.h index bf34a056..f24783f5 100644 --- a/ilist.h +++ b/ilist.h @@ -884,6 +884,19 @@ namespace etl } } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + ilist& operator = (const ilist& rhs) + { + if (&rhs != this) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + protected: //************************************************************************* @@ -941,6 +954,9 @@ namespace etl { p_node_pool->release(&node); } + + // Disable copy construction. + ilist(const ilist&); }; } diff --git a/imap.h b/imap.h index 13e53e74..cd6dd2e9 100644 --- a/imap.h +++ b/imap.h @@ -810,6 +810,20 @@ namespace etl return const_iterator(*this, find_upper_node(root_node, key)); } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + imap& operator = (const imap& rhs) + { + // Skip if doing self assignment + if (this != &rhs) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + protected: //************************************************************************* @@ -1580,6 +1594,9 @@ namespace etl // Return node found (might be nullptr) return found; } + + // Disable copy construction. + imap(const imap&); }; } diff --git a/imultimap.h b/imultimap.h index 81b53f7f..9ace711c 100644 --- a/imultimap.h +++ b/imultimap.h @@ -757,6 +757,20 @@ namespace etl return const_iterator(*this, find_upper_node(root_node, key)); } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + imultimap& operator = (const imultimap& rhs) + { + // Skip if doing self assignment + if (this != &rhs) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + protected: //************************************************************************* @@ -1318,6 +1332,9 @@ namespace etl destroy_data_node(data_node); } // if(found) } + + // Disable copy construction. + imultimap(const imultimap&); }; } diff --git a/imultiset.h b/imultiset.h index 6b7ce644..b1e126b5 100644 --- a/imultiset.h +++ b/imultiset.h @@ -738,6 +738,20 @@ namespace etl return const_iterator(*this, find_upper_node(root_node, key)); } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + imultiset& operator = (const imultiset& rhs) + { + // Skip if doing self assignment + if (this != &rhs) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + protected: //************************************************************************* @@ -1299,6 +1313,9 @@ namespace etl destroy_data_node(data_node); } // if(found) } + + // Disable copy construction. + imultiset(const imultiset&); }; } diff --git a/ipool.h b/ipool.h index d797105b..fdd8620f 100644 --- a/ipool.h +++ b/ipool.h @@ -501,6 +501,12 @@ namespace etl { } + private: + + // Disable copy construction and assignment. + ipool(const ipool&); + ipool& operator =(const ipool&); + T* p_buffer; ibitset& in_use_flags; }; diff --git a/ipriority_queue.h b/ipriority_queue.h index cc829837..0cd40578 100644 --- a/ipriority_queue.h +++ b/ipriority_queue.h @@ -265,6 +265,9 @@ namespace etl private: + // Disable copy construction. + ipriority_queue(const ipriority_queue&); + /// The container specified at instantiation of the priority_queue TContainer container; }; diff --git a/iqueue.h b/iqueue.h index cfdaa141..8a59ab1d 100644 --- a/iqueue.h +++ b/iqueue.h @@ -174,6 +174,19 @@ namespace etl --current_size; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + iqueue& operator = (const iqueue& rhs) + { + if (&rhs != this) + { + clone(rhs); + } + + return *this; + } + protected: //************************************************************************* @@ -201,6 +214,9 @@ namespace etl private: + // Disable copy construction. + iqueue(const iqueue&); + T* p_buffer; ///< The internal buffer. }; } diff --git a/iset.h b/iset.h index cb7c926b..17b989d6 100644 --- a/iset.h +++ b/iset.h @@ -386,7 +386,10 @@ namespace etl //************************************************************************* iset& operator = (const iset& rhs) { - assign(rhs.cbegin(), rhs.cend()); + if (this != &rhs) + { + assign(rhs.cbegin(), rhs.cend()); + } return *this; } @@ -1522,6 +1525,9 @@ namespace etl // Return node found (might be nullptr) return found; } + + // Disable copy construction. + iset(const iset&); }; } diff --git a/istack.h b/istack.h index 6a9386db..f3d0a430 100644 --- a/istack.h +++ b/istack.h @@ -147,6 +147,19 @@ namespace etl --current_size; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + istack& operator = (const istack& rhs) + { + if (&rhs != this) + { + clone(rhs); + } + + return *this; + } + protected: //************************************************************************* @@ -173,6 +186,9 @@ namespace etl private: + // Disable copy construction. + istack(const istack&); + T* p_buffer; ///< The internal buffer. }; } diff --git a/ivector.h b/ivector.h index d2cd81ce..68a9adbf 100644 --- a/ivector.h +++ b/ivector.h @@ -610,6 +610,19 @@ namespace etl return first; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + ivector& operator = (const ivector& rhs) + { + if (&rhs != this) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + protected: //********************************************************************* @@ -666,6 +679,9 @@ namespace etl p_buffer[--current_size].~T(); } + // Disable copy construction. + ivector(const ivector&); + T* p_buffer; }; diff --git a/test/test_bitset.cpp b/test/test_bitset.cpp index c09635b4..b21cd6fd 100644 --- a/test/test_bitset.cpp +++ b/test/test_bitset.cpp @@ -453,6 +453,23 @@ namespace } } + //************************************************************************* + TEST(test_assignment_operator_iterface) + { + etl::bitset<60> data1(0xFFFFFFFFFFFFFFF); + etl::bitset<60> data2; + + etl::ibitset& idata1 = data1; + etl::ibitset& idata2 = data2; + + idata2 = idata1; + + for (size_t i = 0; i < data2.size(); ++i) + { + CHECK_EQUAL(data1.test(i), data2.test(i)); + } + } + //************************************************************************* TEST(test_equality_operator) { diff --git a/test/test_deque.cpp b/test/test_deque.cpp index 52044f05..81dbdb02 100644 --- a/test/test_deque.cpp +++ b/test/test_deque.cpp @@ -39,49 +39,50 @@ SOFTWARE. #include #include -const size_t SIZE = 14; - -typedef TestDataDC DC; -typedef TestDataNDC NDC; - -typedef etl::deque DataDC; -typedef etl::deque DataNDC; - -typedef std::deque Compare_Data; -typedef std::deque Compare_DataDC; - -NDC N0 = NDC("0"); -NDC N1 = NDC("1"); -NDC N2 = NDC("2"); -NDC N3 = NDC("3"); -NDC N4 = NDC("4"); -NDC N5 = NDC("5"); -NDC N6 = NDC("6"); -NDC N7 = NDC("7"); -NDC N8 = NDC("8"); -NDC N9 = NDC("9"); -NDC N10 = NDC("10"); -NDC N11 = NDC("11"); -NDC N12 = NDC("12"); -NDC N13 = NDC("13"); -NDC N14 = NDC("14"); -NDC N15 = NDC("15"); -NDC N16 = NDC("16"); -NDC N17 = NDC("17"); -NDC N999 = NDC("999"); - -std::vector blank_data = { N999, N999, N999, N999, N999, N999, N999, N999, N999, N999, N999, N999, N999, N999 }; -std::vector initial_data = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11, N12, N13 }; -std::vector initial_data_excess = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11, N12, N13, N14 }; -std::vector initial_data_under = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11 }; -std::vector initial_data_small = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; -std::vector insert_data = { N10, N11, N12, N13, N14 }; -std::vector initial_data_dc = { DC("0"), DC("1"), DC("2"), DC("3"), DC("4"), DC("5"), DC("6"), DC("7"), DC("8"), DC("9"), DC("10"), DC("11"), DC("12"), DC("13") }; - namespace { SUITE(test_deque) { + const size_t SIZE = 14; + + typedef TestDataDC DC; + typedef TestDataNDC NDC; + + typedef etl::deque DataDC; + typedef etl::deque DataNDC; + typedef etl::ideque IDataNDC; + + typedef std::deque Compare_Data; + typedef std::deque Compare_DataDC; + + NDC N0 = NDC("0"); + NDC N1 = NDC("1"); + NDC N2 = NDC("2"); + NDC N3 = NDC("3"); + NDC N4 = NDC("4"); + NDC N5 = NDC("5"); + NDC N6 = NDC("6"); + NDC N7 = NDC("7"); + NDC N8 = NDC("8"); + NDC N9 = NDC("9"); + NDC N10 = NDC("10"); + NDC N11 = NDC("11"); + NDC N12 = NDC("12"); + NDC N13 = NDC("13"); + NDC N14 = NDC("14"); + NDC N15 = NDC("15"); + NDC N16 = NDC("16"); + NDC N17 = NDC("17"); + NDC N999 = NDC("999"); + + std::vector blank_data = { N999, N999, N999, N999, N999, N999, N999, N999, N999, N999, N999, N999, N999, N999 }; + std::vector initial_data = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11, N12, N13 }; + std::vector initial_data_excess = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11, N12, N13, N14 }; + std::vector initial_data_under = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11 }; + std::vector initial_data_small = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + std::vector insert_data = { N10, N11, N12, N13, N14 }; + std::vector initial_data_dc = { DC("0"), DC("1"), DC("2"), DC("3"), DC("4"), DC("5"), DC("6"), DC("7"), DC("8"), DC("9"), DC("10"), DC("11"), DC("12"), DC("13") }; + //************************************************************************* TEST(test_constructor) { @@ -144,6 +145,21 @@ namespace CHECK(std::equal(deque1.begin(), deque1.end(), deque2.begin())); } + //************************************************************************* + TEST(test_assignment_interface) + { + DataNDC deque1(initial_data.begin(), initial_data.end()); + DataNDC deque2; + + IDataNDC& ideque1 = deque1; + IDataNDC& ideque2 = deque2; + + ideque2 = ideque1; + + CHECK_EQUAL(deque1.size(), deque2.size()); + CHECK(std::equal(deque1.begin(), deque1.end(), deque2.begin())); + } + //************************************************************************* TEST(test_self_assignment) { diff --git a/test/test_flat_map.cpp b/test/test_flat_map.cpp index 711a9566..37dc8dbc 100644 --- a/test/test_flat_map.cpp +++ b/test/test_flat_map.cpp @@ -72,6 +72,7 @@ namespace typedef etl::flat_map DataDC; typedef etl::flat_map DataNDC; + typedef etl::iflat_map IDataNDC; typedef std::map Compare_DataDC; typedef std::map Compare_DataNDC; @@ -186,6 +187,24 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_interface) + { + DataNDC data1(initial_data.begin(), initial_data.end()); + DataNDC data2; + + IDataNDC& idata1 = data1; + IDataNDC& idata2 = data2; + + idata2 = idata1; + + bool isEqual = Check_Equal(data1.begin(), + data1.end(), + data2.begin()); + + CHECK(isEqual); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_self_assignment) { diff --git a/test/test_flat_multimap.cpp b/test/test_flat_multimap.cpp index bc082030..51e8cc92 100644 --- a/test/test_flat_multimap.cpp +++ b/test/test_flat_multimap.cpp @@ -54,6 +54,7 @@ namespace typedef etl::flat_multimap DataDC; typedef etl::flat_multimap DataNDC; + typedef etl::iflat_multimap IDataNDC; typedef std::multimap Compare_DataDC; typedef std::multimap Compare_DataNDC; @@ -176,6 +177,24 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_interface) + { + DataNDC data1(initial_data.begin(), initial_data.end()); + DataNDC data2; + + IDataNDC& idata1 = data1; + IDataNDC& idata2 = data2; + + idata2 = idata1; + + bool isEqual = Check_Equal(data1.begin(), + data1.end(), + data2.begin()); + + CHECK(isEqual); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_self_assignment) { diff --git a/test/test_flat_multiset.cpp b/test/test_flat_multiset.cpp index f3136e46..2cb4e9ad 100644 --- a/test/test_flat_multiset.cpp +++ b/test/test_flat_multiset.cpp @@ -49,8 +49,9 @@ namespace typedef TestDataDC DC; typedef TestDataNDC NDC; - typedef etl::flat_multiset DataDC; - typedef etl::flat_multiset DataNDC; + typedef etl::flat_multiset DataDC; + typedef etl::flat_multiset DataNDC; + typedef etl::iflat_multiset IDataNDC; typedef std::multiset Compare_DataDC; typedef std::multiset Compare_DataNDC; @@ -150,6 +151,24 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_interface) + { + DataNDC data1(initial_data.begin(), initial_data.end()); + DataNDC data2; + + IDataNDC& idata1 = data1; + IDataNDC& idata2 = data2; + + idata2 = idata1; + + bool isEqual = std::equal(data1.begin(), + data1.end(), + data2.begin()); + + CHECK(isEqual); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_self_assignment) { diff --git a/test/test_flat_set.cpp b/test/test_flat_set.cpp index dc0084ee..37602f5f 100644 --- a/test/test_flat_set.cpp +++ b/test/test_flat_set.cpp @@ -49,8 +49,9 @@ namespace typedef TestDataDC DC; typedef TestDataNDC NDC; - typedef etl::flat_set DataDC; - typedef etl::flat_set DataNDC; + typedef etl::flat_set DataDC; + typedef etl::flat_set DataNDC; + typedef etl::iflat_set IDataNDC; typedef std::set Compare_DataDC; typedef std::set Compare_DataNDC; @@ -143,6 +144,24 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_interface) + { + DataNDC data1(initial_data.begin(), initial_data.end()); + DataNDC data2; + + IDataNDC& idata1 = data1; + IDataNDC& idata2 = data2; + + idata2 = idata1; + + bool isEqual = std::equal(data1.begin(), + data1.end(), + data2.begin()); + + CHECK(isEqual); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_self_assignment) { diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 51d274ea..1f54828c 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -50,6 +50,7 @@ namespace typedef etl::forward_list DataDC; typedef etl::forward_list DataNDC; + typedef etl::iforward_list IDataNDC; typedef std::forward_list CompareDataNDC; typedef std::vector InitialDataNDC; @@ -499,6 +500,22 @@ namespace CHECK(are_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_interface) + { + DataNDC data1(sorted_data.begin(), sorted_data.end()); + DataNDC data2; + + IDataNDC& idata1 = data1; + IDataNDC& idata2 = data2; + + idata2 = idata1; + + bool isEqual = std::equal(data1.begin(), data1.end(), data2.begin()); + + CHECK(isEqual); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_self_assignment) { diff --git a/test/test_list.cpp b/test/test_list.cpp index f795b61b..b1614386 100644 --- a/test/test_list.cpp +++ b/test/test_list.cpp @@ -49,6 +49,7 @@ namespace typedef etl::list DataDC; typedef etl::list DataNDC; + typedef etl::ilist IDataNDC; typedef std::list CompareData; typedef std::vector InitialData; @@ -700,6 +701,25 @@ namespace CHECK(are_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_interface) + { + CompareData compare_data(sorted_data.begin(), sorted_data.end()); + DataNDC data1(sorted_data.begin(), sorted_data.end()); + DataNDC data2; + + IDataNDC& idata1 = data1; + IDataNDC& idata2 = data2; + + idata2 = idata1; + + CHECK_EQUAL(data1.size(), data2.size()); + + are_equal = std::equal(data1.begin(), data1.end(), data2.begin()); + + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_self_assignment) { diff --git a/test/test_map.cpp b/test/test_map.cpp index 4d5b67a9..c18a2351 100644 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -43,9 +43,11 @@ static const size_t SIZE = 10; #define TEST_GREATER_THAN #ifdef TEST_GREATER_THAN typedef etl::map > Data; +typedef etl::imap > IData; typedef std::map > Compare_Data; #else typedef etl::map > Data; +typedef etl::imap > IData; typedef std::map > Compare_Data; #endif @@ -111,7 +113,7 @@ namespace //************************************************************************* struct SetupFixture { - // Maps of predefined data from which to constuct maps used in each test + // Maps of predefined data from which to construct maps used in each test std::map initial_data; std::map excess_data; std::map different_data; @@ -207,6 +209,39 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_interface) + { + Data data1(initial_data.begin(), initial_data.end()); + Data data2; + + IData& idata1 = data1; + IData& idata2 = data2; + + idata2 = idata1; + + bool isEqual = std::equal(data1.begin(), + data1.end(), + data2.begin()); + + CHECK(isEqual); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assignment) + { + Data data(initial_data.begin(), initial_data.end()); + Data other_data(data); + + other_data = other_data; + + bool isEqual = std::equal(data.begin(), + data.end(), + other_data.begin()); + + CHECK(isEqual); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { diff --git a/test/test_multimap.cpp b/test/test_multimap.cpp index 1f8087bf..efc26d4f 100644 --- a/test/test_multimap.cpp +++ b/test/test_multimap.cpp @@ -42,9 +42,11 @@ static const size_t SIZE = 10; #define TEST_GREATER_THAN #ifdef TEST_GREATER_THAN typedef etl::multimap > Data; +typedef etl::imultimap > IData; typedef std::multimap > Compare_Data; #else typedef etl::multimap > Data; +typedef etl::imultimap > IData; typedef std::multimap > Compare_Data; #endif @@ -207,6 +209,39 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_interface) + { + Data data1(initial_data.begin(), initial_data.end()); + Data data2; + + IData& idata1 = data1; + IData& idata2 = data2; + + idata2 = idata1; + + bool isEqual = std::equal(data1.begin(), + data1.end(), + data2.begin()); + + CHECK(isEqual); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assignment) + { + Data data(initial_data.begin(), initial_data.end()); + Data other_data(data); + + other_data = other_data; + + bool isEqual = std::equal(data.begin(), + data.end(), + other_data.begin()); + + CHECK(isEqual); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { diff --git a/test/test_multiset.cpp b/test/test_multiset.cpp index 9c83ab16..64483879 100644 --- a/test/test_multiset.cpp +++ b/test/test_multiset.cpp @@ -41,11 +41,13 @@ static const size_t SIZE = 10; #define TEST_GREATER_THAN #ifdef TEST_GREATER_THAN -typedef etl::multiset > Data; -typedef std::multiset > Compare_Data; +typedef etl::multiset > Data; +typedef etl::imultiset > IData; +typedef std::multiset > Compare_Data; #else -typedef etl::multiset > Data; -typedef std::multiset > Compare_Data; +typedef etl::multiset > Data; +typedef etl::multiset > IData; +typedef std::multiset > Compare_Data; #endif typedef Data::iterator Data_iterator; @@ -199,6 +201,39 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_interface) + { + Data data1(initial_data.begin(), initial_data.end()); + Data data2; + + IData& idata1 = data1; + IData& idata2 = data2; + + idata2 = idata1; + + bool isEqual = std::equal(data1.begin(), + data1.end(), + data2.begin()); + + CHECK(isEqual); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assignment) + { + Data data(initial_data.begin(), initial_data.end()); + Data other_data(data); + + other_data = other_data; + + bool isEqual = std::equal(data.begin(), + data.end(), + other_data.begin()); + + CHECK(isEqual); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { diff --git a/test/test_priority_queue.cpp b/test/test_priority_queue.cpp index e30b8ff0..216663f1 100644 --- a/test/test_priority_queue.cpp +++ b/test/test_priority_queue.cpp @@ -324,6 +324,57 @@ namespace } } + //************************************************************************* + //TEST(test_assignment_interface) + //{ + // etl::priority_queue priority_queue1; + // + // priority_queue1.push(1); + // priority_queue1.push(4); + // priority_queue1.push(3); + // priority_queue1.push(2); + + // etl::priority_queue priority_queue2; + + // etl::ipriority_queue ipriority_queue1 = priority_queue1; + // etl::ipriority_queue ipriority_queue2 = priority_queue2; + + // ipriority_queue2 = ipriority_queue1; + + // CHECK(priority_queue1.size() == priority_queue2.size()); + + // while (!priority_queue1.empty()) + // { + // CHECK_EQUAL(priority_queue1.top(), priority_queue2.top()); + // priority_queue1.pop(); + // priority_queue2.pop(); + // } + //} + + //************************************************************************* + TEST(test_self_assignment) + { + etl::priority_queue priority_queue1; + + priority_queue1.push(1); + priority_queue1.push(4); + priority_queue1.push(3); + priority_queue1.push(2); + + etl::priority_queue priority_queue2 = priority_queue1; + + priority_queue1 = priority_queue1; + + CHECK(priority_queue1.size() == priority_queue2.size()); + + while (!priority_queue1.empty()) + { + CHECK_EQUAL(priority_queue1.top(), priority_queue2.top()); + priority_queue1.pop(); + priority_queue2.pop(); + } + } + //************************************************************************* TEST(test_interface) { @@ -347,32 +398,5 @@ namespace CHECK_EQUAL(compare_priority_queue.size(), ipriority_queue.size()); CHECK_EQUAL(compare_priority_queue.top(), ipriority_queue.top()); } - - //************************************************************************* - TEST(test_self_assignment) - { - etl::priority_queue priority_queue; - - priority_queue.push(2); - priority_queue.push(1); - priority_queue.push(4); - priority_queue.push(3); - - priority_queue = priority_queue; - - CHECK(priority_queue.max_size() == priority_queue.size()); - - CHECK_EQUAL(4, priority_queue.top()); - priority_queue.pop(); - - CHECK_EQUAL(3, priority_queue.top()); - priority_queue.pop(); - - CHECK_EQUAL(2, priority_queue.top()); - priority_queue.pop(); - - CHECK_EQUAL(1, priority_queue.top()); - priority_queue.pop(); - } }; } diff --git a/test/test_queue.cpp b/test/test_queue.cpp index 3b67966a..00bf0a4d 100644 --- a/test/test_queue.cpp +++ b/test/test_queue.cpp @@ -324,6 +324,33 @@ namespace } } + //************************************************************************* + TEST(test_assignment_interface) + { + etl::queue queue1; + + queue1.push(1); + queue1.push(2); + queue1.push(3); + queue1.push(4); + + etl::queue queue2; + + etl::iqueue& iqueue1 = queue1; + etl::iqueue& iqueue2 = queue2; + + iqueue2 = iqueue1; + + CHECK(queue1.size() == queue2.size()); + + while (!queue1.empty()) + { + CHECK_EQUAL(queue1.front(), queue2.front()); + queue1.pop(); + queue2.pop(); + } + } + //************************************************************************* TEST(test_self_assignment) { diff --git a/test/test_set.cpp b/test/test_set.cpp index aa6c1835..6dd2765d 100644 --- a/test/test_set.cpp +++ b/test/test_set.cpp @@ -43,6 +43,7 @@ static const size_t SIZE = 10; #define TEST_GREATER_THAN #ifdef TEST_GREATER_THAN typedef etl::set > Data; +typedef etl::iset > IData; typedef std::set > Compare_Data; #else typedef etl::set > Data; @@ -211,6 +212,39 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_interface) + { + Data data1(initial_data.begin(), initial_data.end()); + Data data2; + + IData& idata1 = data1; + IData& idata2 = data2; + + idata2 = idata1; + + bool isEqual = Check_Equal(data1.begin(), + data1.end(), + data2.begin()); + + CHECK(isEqual); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assignment) + { + Data data(initial_data.begin(), initial_data.end()); + Data otherData(data); + + data = data; + + bool isEqual = Check_Equal(data.begin(), + data.end(), + otherData.begin()); + + CHECK(isEqual); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { diff --git a/test/test_stack.cpp b/test/test_stack.cpp index d5033c67..337a1869 100644 --- a/test/test_stack.cpp +++ b/test/test_stack.cpp @@ -306,6 +306,34 @@ namespace } } + //************************************************************************* + TEST(test_assignment_interface) + { + etl::stack stack1; + + stack1.push(1); + stack1.push(2); + stack1.push(3); + stack1.push(4); + + etl::stack stack2; + + etl::istack& istack1 = stack1; + etl::istack& istack2 = stack2; + + istack2 = istack1; + + CHECK(istack1.size() == stack2.size()); + + while (!stack1.empty()) + { + CHECK_EQUAL(stack1.top(), stack2.top()); + stack1.pop(); + stack2.pop(); + } + } + + //************************************************************************* TEST(test_self_assignment) { diff --git a/test/test_variant.cpp b/test/test_variant.cpp index bf7d580a..463a47d7 100644 --- a/test/test_variant.cpp +++ b/test/test_variant.cpp @@ -274,6 +274,29 @@ namespace CHECK_EQUAL(std::string("Some Text"), variant.get()); } + //************************************************************************* + TEST(test_assignment) + { + test_variant_1 variant1; + test_variant_1 variant2; + + variant1 = 1; + variant2 = variant1; + + CHECK_EQUAL(variant1.get(), variant2.get()); + } + + //************************************************************************* + TEST(test_self_assignment) + { + test_variant_1 variant; + + variant = 1; + variant = variant; + + CHECK_EQUAL(1, variant.get()); + } + //************************************************************************* TEST(TestGetException) { diff --git a/test/test_vector.cpp b/test/test_vector.cpp index cbe94355..392679fd 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -40,8 +40,9 @@ namespace { static const size_t SIZE = 10; - typedef etl::vector Data; - typedef std::vector Compare_Data; + typedef etl::vector Data; + typedef etl::ivector IData; + typedef std::vector Compare_Data; Compare_Data initial_data; Compare_Data less_data; @@ -165,6 +166,24 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_iterface) + { + Data data1(initial_data.begin(), initial_data.end()); + Data data2; + + IData& idata1 = data1; + IData& idata2 = data2; + + idata2 = idata1; + + bool is_equal = std::equal(data1.begin(), + data1.end(), + data2.begin()); + + CHECK(is_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_self_assignment) { diff --git a/vector.h b/vector.h index 83ef45c4..46e61d9b 100644 --- a/vector.h +++ b/vector.h @@ -112,7 +112,6 @@ namespace etl vector(const vector& other) : ivector(reinterpret_cast(&buffer), MAX_SIZE) { - ivector::initialise(); ivector::assign(other.begin(), other.end()); }