diff --git a/include/etl/flat_map.h b/include/etl/flat_map.h index 66ed69b4..548bd97d 100644 --- a/include/etl/flat_map.h +++ b/include/etl/flat_map.h @@ -101,13 +101,15 @@ namespace etl bool operator ()(const value_type& element, key_type key) const { - return key_compare()(element.first, key); + return comp(element.first, key); } bool operator ()(key_type key, const value_type& element) const { - return key_compare()(key, element.first); + return comp(key, element.first); } + + key_compare comp; }; public: @@ -300,7 +302,7 @@ namespace etl std::pair result(i_element, false); // Doesn't already exist? - if ((i_element == end()) || TKeyCompare()(i_element->first, value.first) || TKeyCompare()(value.first, i_element->first)) + if ((i_element == end()) || compare(i_element->first, value.first) || compare(value.first, i_element->first)) { ETL_ASSERT(!refmap_t::full(), ETL_ERROR(flat_map_full)); @@ -764,6 +766,8 @@ namespace etl storage_t& storage; + TKeyCompare compare; + /// Internal debugging. ETL_DECLARE_DEBUG_COUNT; diff --git a/include/etl/flat_multimap.h b/include/etl/flat_multimap.h index e2b9a8c4..a9efbae4 100644 --- a/include/etl/flat_multimap.h +++ b/include/etl/flat_multimap.h @@ -103,13 +103,15 @@ namespace etl bool operator ()(const value_type& element, key_type key) const { - return key_compare()(element.first, key); + return comp(element.first, key); } bool operator ()(key_type key, const value_type& element) const { - return key_compare()(key, element.first); + return comp(key, element.first); } + + key_compare comp; }; public: diff --git a/include/etl/flat_multiset.h b/include/etl/flat_multiset.h index 023a526a..8e946d36 100644 --- a/include/etl/flat_multiset.h +++ b/include/etl/flat_multiset.h @@ -232,7 +232,7 @@ namespace etl ETL_ASSERT(!full(), ETL_ERROR(flat_multiset_full)); - iterator i_element = std::lower_bound(begin(), end(), value, TKeyCompare()); + iterator i_element = std::lower_bound(begin(), end(), value, compare); value_type* pvalue = storage.allocate(); ::new (pvalue) value_type(value); @@ -605,6 +605,8 @@ namespace etl storage_t& storage; + TKeyCompare compare; + /// Internal debugging. ETL_DECLARE_DEBUG_COUNT; diff --git a/include/etl/flat_set.h b/include/etl/flat_set.h index bd58aae5..4d11ae7a 100644 --- a/include/etl/flat_set.h +++ b/include/etl/flat_set.h @@ -233,7 +233,7 @@ namespace etl std::pair result(i_element, false); // Doesn't already exist? - if ((i_element == end()) || TKeyCompare()(*i_element, value) || TKeyCompare()(value, *i_element)) + if ((i_element == end()) || compare(*i_element, value) || compare(value, *i_element)) { ETL_ASSERT(!refset_t::full(), ETL_ERROR(flat_set_full)); @@ -671,6 +671,8 @@ namespace etl storage_t& storage; + TKeyCompare compare; + /// Internal debugging. ETL_DECLARE_DEBUG_COUNT; diff --git a/include/etl/map.h b/include/etl/map.h index d1eb6d93..aa97d223 100644 --- a/include/etl/map.h +++ b/include/etl/map.h @@ -481,7 +481,7 @@ namespace etl { bool operator ()(const key_type& key1, const key_type& key2) const { - return key_compare()(key1, key2); + return compare(key1, key2); } }; @@ -492,7 +492,7 @@ namespace etl { bool operator ()(const value_type& value1, const value_type& value2) const { - return key_compare()(value1.first, value2.first); + return compare(value1.first, value2.first); } }; @@ -524,15 +524,15 @@ namespace etl //************************************************************************* bool node_comp(const Data_Node& node1, const Data_Node& node2) const { - return key_compare()(node1.value.first, node2.value.first); + return compare(node1.value.first, node2.value.first); } bool node_comp(const Data_Node& node, key_parameter_t key) const { - return key_compare()(node.value.first, key); + return compare(node.value.first, key); } bool node_comp(key_parameter_t key, const Data_Node& node) const { - return key_compare()(key, node.value.first); + return compare(key, node.value.first); } private: @@ -540,6 +540,8 @@ namespace etl /// The pool of data nodes used in the map. ipool* p_node_pool; + key_compare compare; + //************************************************************************* /// Downcast a Node* to a Data_Node* //************************************************************************* diff --git a/include/etl/multimap.h b/include/etl/multimap.h index b03dfdf6..c2526e17 100644 --- a/include/etl/multimap.h +++ b/include/etl/multimap.h @@ -638,7 +638,7 @@ namespace etl { bool operator ()(const key_type& key1, const key_type& key2) const { - return key_compare()(key1, key2); + return compare(key1, key2); } }; @@ -649,7 +649,7 @@ namespace etl { bool operator ()(const value_type& value1, const value_type& value2) const { - return key_compare()(value1.first, value2.first); + return compare(value1.first, value2.first); } }; @@ -676,17 +676,17 @@ namespace etl //************************************************************************* bool node_comp(const Data_Node& node1, const Data_Node& node2) const { - return key_compare()(node1.value.first, node2.value.first); + return compare(node1.value.first, node2.value.first); } bool node_comp(const Data_Node& node, key_parameter_t key) const { - return key_compare()(node.value.first, key); + return compare(node.value.first, key); } bool node_comp(key_parameter_t key, const Data_Node& node) const { - return key_compare()(key, node.value.first); + return compare(key, node.value.first); } private: @@ -694,6 +694,8 @@ namespace etl /// The pool of data nodes used in the multimap. ipool* p_node_pool; + key_compare compare; + //************************************************************************* /// Downcast a Node* to a Data_Node* //************************************************************************* diff --git a/include/etl/multiset.h b/include/etl/multiset.h index 5c2b23d9..3c8e4d82 100644 --- a/include/etl/multiset.h +++ b/include/etl/multiset.h @@ -636,7 +636,7 @@ namespace etl { bool operator ()(key_type& key1, key_type& key2) const { - return key_compare()(key1, key2); + return compare(key1, key2); } }; @@ -647,7 +647,7 @@ namespace etl { bool operator ()(value_type& value1, value_type& value2) const { - return value_compare()(value1, value2); + return compare(value1, value2); } }; @@ -674,15 +674,15 @@ namespace etl //************************************************************************* bool node_comp(const Data_Node& node1, const Data_Node& node2) const { - return key_compare()(node1.value, node2.value); + return compare(node1.value, node2.value); } bool node_comp(const Data_Node& node, key_parameter_t key) const { - return key_compare()(node.value, key); + return compare(node.value, key); } bool node_comp(key_parameter_t key, const Data_Node& node) const { - return key_compare()(key, node.value); + return compare(key, node.value); } private: @@ -690,6 +690,8 @@ namespace etl /// The pool of data nodes used in the multiset. ipool* p_node_pool; + key_compare compare; + //************************************************************************* /// Downcast a Node* to a Data_Node* //************************************************************************* diff --git a/include/etl/priority_queue.h b/include/etl/priority_queue.h index 6e0474b3..34bf15a3 100644 --- a/include/etl/priority_queue.h +++ b/include/etl/priority_queue.h @@ -165,7 +165,7 @@ namespace etl // Put element at end container.push_back(value); // Make elements in container into heap - std::push_heap(container.begin(), container.end(), TCompare()); + std::push_heap(container.begin(), container.end(), compare); } //************************************************************************* @@ -182,7 +182,7 @@ namespace etl // Put element at end container.emplace_back(value1); // Make elements in container into heap - std::push_heap(container.begin(), container.end(), TCompare()); + std::push_heap(container.begin(), container.end(), compare); } //************************************************************************* @@ -199,7 +199,7 @@ namespace etl // Put element at end container.emplace_back(value1, value2); // Make elements in container into heap - std::push_heap(container.begin(), container.end(), TCompare()); + std::push_heap(container.begin(), container.end(), compare); } //************************************************************************* @@ -216,7 +216,7 @@ namespace etl // Put element at end container.emplace_back(value1, value2, value3); // Make elements in container into heap - std::push_heap(container.begin(), container.end(), TCompare()); + std::push_heap(container.begin(), container.end(), compare); } //************************************************************************* @@ -233,7 +233,7 @@ namespace etl // Put element at end container.emplace_back(value1, value2, value3, value4); // Make elements in container into heap - std::push_heap(container.begin(), container.end(), TCompare()); + std::push_heap(container.begin(), container.end(), compare); } //************************************************************************* @@ -256,7 +256,7 @@ namespace etl clear(); container.assign(first, last); - std::make_heap(container.begin(), container.end(), TCompare()); + std::make_heap(container.begin(), container.end(), compare); } //************************************************************************* @@ -266,7 +266,7 @@ namespace etl void pop() { // Move largest element to end - std::pop_heap(container.begin(), container.end(), TCompare()); + std::pop_heap(container.begin(), container.end(), compare); // Actually remove largest element at end container.pop_back(); } @@ -356,6 +356,8 @@ namespace etl /// The container specified at instantiation of the priority_queue TContainer container; + + TCompare compare; }; //*************************************************************************** diff --git a/include/etl/reference_flat_map.h b/include/etl/reference_flat_map.h index 5ff5a908..840b7497 100644 --- a/include/etl/reference_flat_map.h +++ b/include/etl/reference_flat_map.h @@ -329,19 +329,21 @@ namespace etl //********************************************************************* /// How to compare elements and keys. //********************************************************************* - class compare + class Compare { public: bool operator ()(const value_type& element, key_type key) const { - return key_compare()(element.first, key); + return comp(element.first, key); } bool operator ()(key_type key, const value_type& element) const { - return key_compare()(key, element.first); + return comp(key, element.first); } + + key_compare comp; }; public: @@ -690,7 +692,7 @@ namespace etl //********************************************************************* iterator lower_bound(key_parameter_t key) { - return std::lower_bound(begin(), end(), key, compare()); + return std::lower_bound(begin(), end(), key, compare); } //********************************************************************* @@ -700,7 +702,7 @@ namespace etl //********************************************************************* const_iterator lower_bound(key_parameter_t key) const { - return std::lower_bound(cbegin(), cend(), key, compare()); + return std::lower_bound(cbegin(), cend(), key, compare); } //********************************************************************* @@ -710,7 +712,7 @@ namespace etl //********************************************************************* iterator upper_bound(key_parameter_t key) { - return std::upper_bound(begin(), end(), key, compare()); + return std::upper_bound(begin(), end(), key, compare); } //********************************************************************* @@ -720,7 +722,7 @@ namespace etl //********************************************************************* const_iterator upper_bound(key_parameter_t key) const { - return std::upper_bound(begin(), end(), key, compare()); + return std::upper_bound(begin(), end(), key, compare); } //********************************************************************* @@ -730,9 +732,9 @@ namespace etl //********************************************************************* std::pair equal_range(key_parameter_t key) { - iterator i_lower = std::lower_bound(begin(), end(), key, compare()); + iterator i_lower = std::lower_bound(begin(), end(), key, compare); - return std::make_pair(i_lower, std::upper_bound(i_lower, end(), key, compare())); + return std::make_pair(i_lower, std::upper_bound(i_lower, end(), key, compare)); } //********************************************************************* @@ -742,9 +744,9 @@ namespace etl //********************************************************************* std::pair equal_range(key_parameter_t key) const { - const_iterator i_lower = std::lower_bound(cbegin(), cend(), key, compare()); + const_iterator i_lower = std::lower_bound(cbegin(), cend(), key, compare); - return std::make_pair(i_lower, std::upper_bound(i_lower, cend(), key, compare())); + return std::make_pair(i_lower, std::upper_bound(i_lower, cend(), key, compare)); } //************************************************************************* @@ -855,6 +857,8 @@ namespace etl lookup_t& lookup; + Compare compare; + //************************************************************************* /// Destructor. //************************************************************************* diff --git a/include/etl/reference_flat_multimap.h b/include/etl/reference_flat_multimap.h index 3088aa75..88adde96 100644 --- a/include/etl/reference_flat_multimap.h +++ b/include/etl/reference_flat_multimap.h @@ -304,19 +304,21 @@ namespace etl //********************************************************************* /// How to compare elements and keys. //********************************************************************* - class compare + class Compare { public: bool operator ()(const value_type& element, key_type key) const { - return key_compare()(element.first, key); + return comp(element.first, key); } bool operator ()(key_type key, const value_type& element) const { - return key_compare()(key, element.first); + return comp(key, element.first); } + + key_compare comp; }; public: @@ -612,7 +614,7 @@ namespace etl //********************************************************************* iterator lower_bound(key_parameter_t key) { - return std::lower_bound(begin(), end(), key, compare()); + return std::lower_bound(begin(), end(), key, compare); } //********************************************************************* @@ -622,7 +624,7 @@ namespace etl //********************************************************************* const_iterator lower_bound(key_parameter_t key) const { - return std::lower_bound(cbegin(), cend(), key, compare()); + return std::lower_bound(cbegin(), cend(), key, compare); } //********************************************************************* @@ -632,7 +634,7 @@ namespace etl //********************************************************************* iterator upper_bound(key_parameter_t key) { - return std::upper_bound(begin(), end(), key, compare()); + return std::upper_bound(begin(), end(), key, compare); } //********************************************************************* @@ -642,7 +644,7 @@ namespace etl //********************************************************************* const_iterator upper_bound(key_parameter_t key) const { - return std::upper_bound(begin(), end(), key, compare()); + return std::upper_bound(begin(), end(), key, compare); } //********************************************************************* @@ -652,9 +654,9 @@ namespace etl //********************************************************************* std::pair equal_range(key_parameter_t key) { - iterator i_lower = std::lower_bound(begin(), end(), key, compare()); + iterator i_lower = std::lower_bound(begin(), end(), key, compare); - return std::make_pair(i_lower, std::upper_bound(i_lower, end(), key, compare())); + return std::make_pair(i_lower, std::upper_bound(i_lower, end(), key, compare)); } //********************************************************************* @@ -664,9 +666,9 @@ namespace etl //********************************************************************* std::pair equal_range(key_parameter_t key) const { - const_iterator i_lower = std::lower_bound(cbegin(), cend(), key, compare()); + const_iterator i_lower = std::lower_bound(cbegin(), cend(), key, compare); - return std::make_pair(i_lower, std::upper_bound(i_lower, cend(), key, compare())); + return std::make_pair(i_lower, std::upper_bound(i_lower, cend(), key, compare)); } //************************************************************************* @@ -768,6 +770,8 @@ namespace etl lookup_t& lookup; + Compare compare; + //************************************************************************* /// Destructor. //************************************************************************* diff --git a/include/etl/reference_flat_multiset.h b/include/etl/reference_flat_multiset.h index 11f89c8f..1cf5ca32 100644 --- a/include/etl/reference_flat_multiset.h +++ b/include/etl/reference_flat_multiset.h @@ -460,9 +460,9 @@ namespace etl { std::pair result(end(), false); - ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_multiset_full)); + ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_multiset_full)); - iterator i_element = std::lower_bound(begin(), end(), value, TKeyCompare()); + iterator i_element = std::lower_bound(begin(), end(), value, compare); if (i_element == end()) { @@ -566,7 +566,7 @@ namespace etl //********************************************************************* iterator find(parameter_t key) { - iterator itr = std::lower_bound(begin(), end(), key, TKeyCompare()); + iterator itr = std::lower_bound(begin(), end(), key, compare); if (itr != end()) { @@ -590,7 +590,7 @@ namespace etl //********************************************************************* const_iterator find(parameter_t key) const { - const_iterator itr = std::lower_bound(begin(), end(), key, TKeyCompare()); + const_iterator itr = std::lower_bound(begin(), end(), key, compare); if (itr != end()) { @@ -626,7 +626,7 @@ namespace etl //********************************************************************* iterator lower_bound(parameter_t key) { - return std::lower_bound(begin(), end(), key, TKeyCompare()); + return std::lower_bound(begin(), end(), key, compare); } //********************************************************************* @@ -636,7 +636,7 @@ namespace etl //********************************************************************* const_iterator lower_bound(parameter_t key) const { - return std::lower_bound(cbegin(), cend(), key, TKeyCompare()); + return std::lower_bound(cbegin(), cend(), key, compare); } //********************************************************************* @@ -646,7 +646,7 @@ namespace etl //********************************************************************* iterator upper_bound(parameter_t key) { - return std::upper_bound(begin(), end(), key, TKeyCompare()); + return std::upper_bound(begin(), end(), key, compare); } //********************************************************************* @@ -656,7 +656,7 @@ namespace etl //********************************************************************* const_iterator upper_bound(parameter_t key) const { - return std::upper_bound(cbegin(), cend(), key, TKeyCompare()); + return std::upper_bound(cbegin(), cend(), key, compare); } //********************************************************************* @@ -666,7 +666,7 @@ namespace etl //********************************************************************* std::pair equal_range(parameter_t key) { - return std::equal_range(begin(), end(), key, TKeyCompare()); + return std::equal_range(begin(), end(), key, compare); } //********************************************************************* @@ -676,7 +676,7 @@ namespace etl //********************************************************************* std::pair equal_range(parameter_t key) const { - return std::equal_range(begin(), end(), key, TKeyCompare()); + return std::equal_range(begin(), end(), key, compare); } //************************************************************************* @@ -783,6 +783,8 @@ namespace etl lookup_t& lookup; + TKeyCompare compare; + //************************************************************************* /// Destructor. //************************************************************************* diff --git a/include/etl/reference_flat_set.h b/include/etl/reference_flat_set.h index 0247ffc5..cfbc4793 100644 --- a/include/etl/reference_flat_set.h +++ b/include/etl/reference_flat_set.h @@ -546,7 +546,7 @@ namespace etl //********************************************************************* iterator find(parameter_t key) { - iterator itr = std::lower_bound(begin(), end(), key, TKeyCompare()); + iterator itr = std::lower_bound(begin(), end(), key, compare); if (itr != end()) { @@ -570,7 +570,7 @@ namespace etl //********************************************************************* const_iterator find(parameter_t key) const { - const_iterator itr = std::lower_bound(begin(), end(), key, TKeyCompare()); + const_iterator itr = std::lower_bound(begin(), end(), key, compare); if (itr != end()) { @@ -604,7 +604,7 @@ namespace etl //********************************************************************* iterator lower_bound(parameter_t key) { - return std::lower_bound(begin(), end(), key, TKeyCompare()); + return std::lower_bound(begin(), end(), key, compare); } //********************************************************************* @@ -614,7 +614,7 @@ namespace etl //********************************************************************* const_iterator lower_bound(parameter_t key) const { - return std::lower_bound(cbegin(), cend(), key, TKeyCompare()); + return std::lower_bound(cbegin(), cend(), key, compare); } //********************************************************************* @@ -624,7 +624,7 @@ namespace etl //********************************************************************* iterator upper_bound(parameter_t key) { - return std::upper_bound(begin(), end(), key, TKeyCompare()); + return std::upper_bound(begin(), end(), key, compare); } //********************************************************************* @@ -634,7 +634,7 @@ namespace etl //********************************************************************* const_iterator upper_bound(parameter_t key) const { - return std::upper_bound(cbegin(), cend(), key, TKeyCompare()); + return std::upper_bound(cbegin(), cend(), key, compare); } //********************************************************************* @@ -644,7 +644,7 @@ namespace etl //********************************************************************* std::pair equal_range(parameter_t key) { - return std::equal_range(begin(), end(), key, TKeyCompare()); + return std::equal_range(begin(), end(), key, compare); } //********************************************************************* @@ -654,7 +654,7 @@ namespace etl //********************************************************************* std::pair equal_range(parameter_t key) const { - return std::upper_bound(cbegin(), cend(), key, TKeyCompare()); + return std::upper_bound(cbegin(), cend(), key, compare); } //************************************************************************* @@ -745,7 +745,7 @@ namespace etl result.first = i_element; // Existing element? - if (TKeyCompare()(value, *i_element) || TKeyCompare()(*i_element, value)) + if (compare(value, *i_element) || compare(*i_element, value)) { // A new one. ETL_ASSERT(!lookup.full(), ETL_ERROR(flat_set_full)); @@ -765,6 +765,8 @@ namespace etl lookup_t& lookup; + TKeyCompare compare; + //************************************************************************* /// Destructor. //************************************************************************* diff --git a/include/etl/set.h b/include/etl/set.h index 31f0ff7d..38049700 100644 --- a/include/etl/set.h +++ b/include/etl/set.h @@ -474,7 +474,7 @@ namespace etl { bool operator ()(key_type& key1, key_type& key2) const { - return key_compare()(key1, key2); + return compare(key1, key2); } }; @@ -485,7 +485,7 @@ namespace etl { bool operator ()(value_type& value1, value_type& value2) const { - return value_compare()(value1, value2); + return compare(value1, value2); } }; @@ -512,17 +512,17 @@ namespace etl //************************************************************************* bool node_comp(const Data_Node& node1, const Data_Node& node2) const { - return key_compare()(node1.value, node2.value); + return compare(node1.value, node2.value); } bool node_comp(const Data_Node& node, key_parameter_t key) const { - return key_compare()(node.value, key); + return compare(node.value, key); } bool node_comp(key_parameter_t key, const Data_Node& node) const { - return key_compare()(key, node.value); + return compare(key, node.value); } private: @@ -530,6 +530,8 @@ namespace etl /// The pool of data nodes used in the set. etl::ipool* p_node_pool; + key_compare compare; + //************************************************************************* /// Downcast a Node* to a Data_Node* //************************************************************************* diff --git a/include/etl/variant.h b/include/etl/variant.h index a539fe3f..26e9c124 100644 --- a/include/etl/variant.h +++ b/include/etl/variant.h @@ -874,18 +874,18 @@ namespace etl /// Calls the supplied reader instance. /// The 'read' function appropriate to the current type is called with the stored value. //*************************************************************************** - void call(reader& reader) + void call(reader& r) { switch (type_id) { - case 0: reader.read(static_cast(data)); break; - case 1: reader.read(static_cast(data)); break; - case 2: reader.read(static_cast(data)); break; - case 3: reader.read(static_cast(data)); break; - case 4: reader.read(static_cast(data)); break; - case 5: reader.read(static_cast(data)); break; - case 6: reader.read(static_cast(data)); break; - case 7: reader.read(static_cast(data)); break; + case 0: r.read(static_cast(data)); break; + case 1: r.read(static_cast(data)); break; + case 2: r.read(static_cast(data)); break; + case 3: r.read(static_cast(data)); break; + case 4: r.read(static_cast(data)); break; + case 5: r.read(static_cast(data)); break; + case 6: r.read(static_cast(data)); break; + case 7: r.read(static_cast(data)); break; default: break; } }