From c35f962e6fb496097c6462b1e4f4f9dcfee1320c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 24 Feb 2018 10:55:36 +0000 Subject: [PATCH 1/7] Merge remote-tracking branch 'origin/master' into development # Conflicts: # test/codeblocks/ETL.layout # test/test_pool.cpp --- src/multimap.h | 134 ++++++++++++++++++++++----------------------- test/test_pool.cpp | 2 +- 2 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/multimap.h b/src/multimap.h index b5a5a897..ebb93c89 100644 --- a/src/multimap.h +++ b/src/multimap.h @@ -194,8 +194,8 @@ namespace etl /// Constructor //*********************************************************************** Node() : - weight(kNeither), - dir(kNeither) + weight((uint_least8_t) kNeither), + dir((uint_least8_t) kNeither) { } @@ -204,8 +204,8 @@ namespace etl //*********************************************************************** void mark_as_leaf() { - weight = kNeither; - dir = kNeither; + weight = (uint_least8_t) kNeither; + dir = (uint_least8_t) kNeither; parent = nullptr; children[0] = nullptr; children[1] = nullptr; @@ -245,13 +245,13 @@ namespace etl Node* weight_node = critical_node->children[critical_node->dir]; while (weight_node) { - // Keep going until we reach a terminal node (dir == kNeither) - if (kNeither != weight_node->dir) + // Keep going until we reach a terminal node (dir == (uint_least8_t) kNeither) + if ((uint_least8_t) kNeither != weight_node->dir) { // Does this insert balance the previous weight factor value? if (weight_node->weight == 1 - weight_node->dir) { - weight_node->weight = kNeither; + weight_node->weight = (uint_least8_t) kNeither; } else { @@ -269,14 +269,14 @@ namespace etl } // while(weight_node) // Step 2: Update weight for critical_node or rotate tree to balance node - if (kNeither == critical_node->weight) + if ((uint_least8_t) kNeither == critical_node->weight) { critical_node->weight = critical_node->dir; } // If direction is different than weight, then it will now be balanced else if (critical_node->dir != critical_node->weight) { - critical_node->weight = kNeither; + critical_node->weight = (uint_least8_t) kNeither; } // Rotate is required to balance the tree at the critical node else @@ -330,12 +330,12 @@ namespace etl new_root->dir = 1 - dir; // Clear weight factor from current position - position->weight = kNeither; + position->weight = (uint_least8_t) kNeither; // Position's parent becomes new_root position->parent = new_root; position = new_root; // Clear weight factor from new root - position->weight = kNeither; + position->weight = (uint_least8_t) kNeither; } //************************************************************************* @@ -358,7 +358,7 @@ namespace etl // Capture new root (either E or D depending on dir) Node* new_root = position->children[dir]->children[1 - dir]; // Set weight factor for B or C based on F or G existing and being a different than dir - position->children[dir]->weight = third != kNeither && third != dir ? dir : kNeither; + position->children[dir]->weight = third != (uint_least8_t) kNeither && third != dir ? dir : (uint_least8_t) kNeither; // Detach new root from its tree (replace with new roots child) position->children[dir]->children[1 - dir] = new_root->children[dir]; @@ -373,7 +373,7 @@ namespace etl position->children[dir]->parent = new_root; // Set weight factor for A based on F or G - position->weight = third != kNeither && third == dir ? 1 - dir : kNeither; + position->weight = third != (uint_least8_t) kNeither && third == dir ? 1 - dir : (uint_least8_t) kNeither; // Move new root's right tree to current roots left tree position->children[dir] = new_root->children[1 - dir]; @@ -391,7 +391,7 @@ namespace etl position->parent = new_root; position = new_root; // Clear weight factor for new current position - position->weight = kNeither; + position->weight = (uint_least8_t) kNeither; } //************************************************************************* @@ -402,10 +402,10 @@ namespace etl if (position) { // Is there a tree on the right? then find the minimum of that tree - if (position->children[kRight]) + if (position->children[(uint_least8_t) kRight]) { // Return minimum node found - position = find_limit_node(position->children[kRight], kLeft); + position = find_limit_node(position->children[(uint_least8_t) kRight], kLeft); } // Otherwise find the parent of this node else @@ -418,7 +418,7 @@ namespace etl // Find parent of current position parent = position->parent; // find_parent_node(root_node, position); // Repeat while previous position was on right side of parent tree - } while (parent && parent->children[kRight] == position); + } while (parent && parent->children[(uint_least8_t) kRight] == position); // Set parent node as the next position position = parent; @@ -434,10 +434,10 @@ namespace etl if (position) { // Is there a tree on the right? then find the minimum of that tree - if (position->children[kRight]) + if (position->children[(uint_least8_t) kRight]) { // Return minimum node found - position = find_limit_node(position->children[kRight], kLeft); + position = find_limit_node(position->children[(uint_least8_t) kRight], kLeft); } // Otherwise find the parent of this node else @@ -450,7 +450,7 @@ namespace etl // Find parent of current position parent = position->parent; // Repeat while previous position was on right side of parent tree - } while (parent && parent->children[kRight] == position); + } while (parent && parent->children[(uint_least8_t) kRight] == position); // Set parent node as the next position position = parent; @@ -472,10 +472,10 @@ namespace etl else { // Is there a tree on the left? then find the maximum of that tree - if (position->children[kLeft]) + if (position->children[(uint_least8_t) kLeft]) { // Return maximum node found - position = find_limit_node(position->children[kLeft], kRight); + position = find_limit_node(position->children[(uint_least8_t) kLeft], kRight); } // Otherwise find the parent of this node else @@ -488,7 +488,7 @@ namespace etl // Find parent of current position parent = position->parent; // Repeat while previous position was on left side of parent tree - } while (parent && parent->children[kLeft] == position); + } while (parent && parent->children[(uint_least8_t) kLeft] == position); // Set parent node as the next position position = parent; @@ -510,10 +510,10 @@ namespace etl else { // Is there a tree on the left? then find the maximum of that tree - if (position->children[kLeft]) + if (position->children[(uint_least8_t) kLeft]) { // Return maximum node found - position = find_limit_node(position->children[kLeft], kRight); + position = find_limit_node(position->children[(uint_least8_t) kLeft], kRight); } // Otherwise find the parent of this node else @@ -526,7 +526,7 @@ namespace etl // Find parent of current position parent = position->parent; // Repeat while previous position was on left side of parent tree - } while (parent && parent->children[kLeft] == position); + } while (parent && parent->children[(uint_least8_t) kLeft] == position); // Set parent node as the next position position = parent; @@ -589,15 +589,15 @@ namespace etl // Point swap node to detached node's parent, children and weight swap->parent = detached->parent; - swap->children[kLeft] = detached->children[kLeft]; - swap->children[kRight] = detached->children[kRight]; - if (swap->children[kLeft]) + swap->children[(uint_least8_t) kLeft] = detached->children[(uint_least8_t) kLeft]; + swap->children[(uint_least8_t) kRight] = detached->children[(uint_least8_t) kRight]; + if (swap->children[(uint_least8_t) kLeft]) { - swap->children[kLeft]->parent = swap; + swap->children[(uint_least8_t) kLeft]->parent = swap; } - if (swap->children[kRight]) + if (swap->children[(uint_least8_t) kRight]) { - swap->children[kRight]->parent = swap; + swap->children[(uint_least8_t) kRight]->parent = swap; } swap->weight = detached->weight; } @@ -1412,18 +1412,18 @@ namespace etl if (node_comp(key, data_node)) { // Keep searching for the node on the left - position = position->children[kLeft]; + position = position->children[(uint_least8_t) kLeft]; } else if (node_comp(data_node, key)) { // Keep searching for the node on the right - position = position->children[kRight]; + position = position->children[(uint_least8_t) kRight]; } else { // We found one, keep looking for more on the left found = position; - position = position->children[kLeft]; + position = position->children[(uint_least8_t) kLeft]; } } @@ -1445,18 +1445,18 @@ namespace etl if (node_comp(key, data_node)) { // Keep searching for the node on the left - position = position->children[kLeft]; + position = position->children[(uint_least8_t) kLeft]; } else if (node_comp(data_node, key)) { // Keep searching for the node on the right - position = position->children[kRight]; + position = position->children[(uint_least8_t) kRight]; } else { // We found one, keep looking for more on the left found = position; - position = position->children[kLeft]; + position = position->children[(uint_least8_t) kLeft]; } } @@ -1479,9 +1479,9 @@ namespace etl if (node_comp(key, data_node)) { lower_node = position; - if (position->children[kLeft]) + if (position->children[(uint_least8_t) kLeft]) { - position = position->children[kLeft]; + position = position->children[(uint_least8_t) kLeft]; } else { @@ -1491,13 +1491,13 @@ namespace etl } else if (node_comp(data_node, key)) { - position = position->children[kRight]; + position = position->children[(uint_least8_t) kRight]; } else { // Make note of current position, but keep looking to left for more lower_node = position; - position = position->children[kLeft]; + position = position->children[(uint_least8_t) kLeft]; } } @@ -1521,15 +1521,15 @@ namespace etl // Compare the key value to the current upper node key value if (node_comp(data_node, key)) { - position = position->children[kRight]; + position = position->children[(uint_least8_t) kRight]; } else if (node_comp(key, data_node)) { upper_node = position; // If a node equal to key hasn't been found go left - if (!found && position->children[kLeft]) + if (!found && position->children[(uint_least8_t) kLeft]) { - position = position->children[kLeft]; + position = position->children[(uint_least8_t) kLeft]; } else { @@ -1566,8 +1566,8 @@ namespace etl while (found) { // Search for critical weight node (all nodes whose weight factor - // is set to kNeither (balanced) - if (kNeither != found->weight) + // is set to (uint_least8_t) kNeither (balanced) + if ((uint_least8_t) kNeither != found->weight) { critical_node = found; } @@ -1579,27 +1579,27 @@ namespace etl if (node_comp(node, found_data_node)) { // Update direction taken to insert new node in parent node - found->dir = kLeft; + found->dir = (uint_least8_t) kLeft; } // Is the node provided to the right of the current position? else if (node_comp(found_data_node, node)) { // Update direction taken to insert new node in parent node - found->dir = kRight; + found->dir = (uint_least8_t) kRight; } else { // Update direction taken to insert new node in parent (and // duplicate) node to the right. - found->dir = kRight; + found->dir = (uint_least8_t) kRight; } // Is there a child of this parent node? if (found->children[found->dir]) { // Will this node be the parent of the next critical node whose - // weight factor is set to kNeither (balanced)? - if (kNeither != found->children[found->dir]->weight) + // weight factor is set to (uint_least8_t) kNeither (balanced)? + if ((uint_least8_t) kNeither != found->children[found->dir]->weight) { critical_parent_node = found; } @@ -1675,7 +1675,7 @@ namespace etl { // Which direction does parent use to get to this node? node->parent->dir = - node->parent->children[kLeft] == node ? kLeft : kRight; + node->parent->children[(uint_least8_t) kLeft] == node ? (uint_least8_t) kLeft : (uint_least8_t) kRight; // Make this nodes parent the next node node = node->parent; @@ -1697,20 +1697,20 @@ namespace etl if (node == found) { // Update the direction towards a replacement node at the found node - node->dir = node->children[kLeft] ? kLeft : kRight; + node->dir = node->children[(uint_least8_t) kLeft] ? (uint_least8_t) kLeft : (uint_least8_t) kRight; // Exit loop and proceed with step 3 break; } else { - // If this nodes weight is kNeither or we are taking the shorter path + // If this nodes weight is (uint_least8_t) kNeither or we are taking the shorter path // to the next node and our sibling (on longer path) is balanced then // we need to update the balance node to this node but all our // ancestors will not require rebalancing - if ((node->weight == kNeither) || + if ((node->weight == (uint_least8_t) kNeither) || (node->weight == (1 - node->dir) && - node->children[1 - node->dir]->weight == kNeither)) + node->children[1 - node->dir]->weight == (uint_least8_t) kNeither)) { // Update balance node to this node balance = node; @@ -1737,13 +1737,13 @@ namespace etl break; } - // If this nodes weight is kNeither or we are taking the shorter path + // If this nodes weight is (uint_least8_t) kNeither or we are taking the shorter path // to the next node and our sibling (on longer path) is balanced then // we need to update the balance node to this node but all our // ancestors will not require rebalancing - if ((node->weight == kNeither) || + if ((node->weight == (uint_least8_t) kNeither) || (node->weight == (1 - node->dir) && - node->children[1 - node->dir]->weight == kNeither)) + node->children[1 - node->dir]->weight == (uint_least8_t) kNeither)) { // Update balance node to this node balance = node; @@ -1759,17 +1759,17 @@ namespace etl if (node_comp(data_node, replace_data_node)) { // Update the direction to the replace node - node->dir = kLeft; + node->dir = (uint_least8_t) kLeft; } else if (node_comp(replace_data_node, data_node)) { // Update the direction to the replace node - node->dir = kRight; + node->dir = (uint_least8_t) kRight; } else { // Update the direction to the replace node - node->dir = node->children[kLeft] ? kLeft : kRight; + node->dir = node->children[(uint_least8_t) kLeft] ? (uint_least8_t) kLeft : (uint_least8_t) kRight; } } // while(node) @@ -1783,9 +1783,9 @@ namespace etl break; } - // If balance node is balanced already (kNeither) then just imbalance + // If balance node is balanced already ((uint_least8_t) kNeither) then just imbalance // the node in the opposite direction of the node being removed - if (balance->weight == kNeither) + if (balance->weight == (uint_least8_t) kNeither) { balance->weight = 1 - balance->dir; } @@ -1793,7 +1793,7 @@ namespace etl // node being removed then the node now becomes balanced else if (balance->weight == balance->dir) { - balance->weight = kNeither; + balance->weight = (uint_least8_t) kNeither; } // Otherwise a rotation is required at this node else @@ -1816,7 +1816,7 @@ namespace etl } // Already balanced, rebalance and make it heavy in opposite // direction of the node being removed - else if (weight == kNeither) + else if (weight == (uint_least8_t) kNeither) { // Is the root node being rebalanced (no parent) if (balance->parent == nullptr) diff --git a/test/test_pool.cpp b/test/test_pool.cpp index 4ae73d68..57c5363c 100644 --- a/test/test_pool.cpp +++ b/test/test_pool.cpp @@ -132,7 +132,7 @@ namespace return (lhs.a == rhs.a) && (lhs.b == rhs.b) && (lhs.c == rhs.c) && (lhs.d == rhs.d); } - std::ostream& operator <<(std::ostream& os, const D0& d) + std::ostream& operator <<(std::ostream& os, const D0&) { return os; } From d1adfab03c2f01bf717c7545ebb627fc6776538c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 25 Feb 2018 13:21:00 +0000 Subject: [PATCH 2/7] Remove more GCC warnings from use of -Wextra --- src/multiset.h | 2 +- src/type_lookup.h | 36 ++++++++++++++++++------------------ test/murmurhash3.cpp | 2 ++ 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/multiset.h b/src/multiset.h index abdfd2e5..3d58d186 100644 --- a/src/multiset.h +++ b/src/multiset.h @@ -566,7 +566,7 @@ namespace etl // Capture new root (either E or D depending on dir) Node* new_root = position->children[dir]->children[1 - dir]; // Set weight factor for B or C based on F or G existing and being a different than dir - position->children[dir]->weight = third != kNeither && third != dir ? dir : kNeither; + position->children[dir]->weight = third != kNeither && third != dir ? dir : uint_least8_t(kNeither); // Detach new root from its tree (replace with new roots child) position->children[dir]->children[1 - dir] = new_root->children[dir]; diff --git a/src/type_lookup.h b/src/type_lookup.h index 1d8a98dc..01d254cf 100644 --- a/src/type_lookup.h +++ b/src/type_lookup.h @@ -101,7 +101,7 @@ namespace etl template struct type_from_id { - typedef + typedef typename etl::conditional::value ? T1::ID : - (unsigned int) etl::is_same::value ? T2::ID : - (unsigned int) etl::is_same::value ? T3::ID : - (unsigned int) etl::is_same::value ? T4::ID : - (unsigned int) etl::is_same::value ? T5::ID : - (unsigned int) etl::is_same::value ? T6::ID : - (unsigned int) etl::is_same::value ? T7::ID : - (unsigned int) etl::is_same::value ? T8::ID : - (unsigned int) etl::is_same::value ? T9::ID : - (unsigned int) etl::is_same::value ? T10::ID : - (unsigned int) etl::is_same::value ? T11::ID : - (unsigned int) etl::is_same::value ? T12::ID : - (unsigned int) etl::is_same::value ? T13::ID : - (unsigned int) etl::is_same::value ? T14::ID : - (unsigned int) etl::is_same::value ? T15::ID : - (unsigned int) etl::is_same::value ? T16::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T1::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T2::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T3::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T4::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T5::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T6::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T7::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T8::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T9::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T10::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T11::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T12::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T13::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T14::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T15::ID : + (unsigned int) etl::is_same::value ? (unsigned int)T16::ID : (unsigned int) UNKNOWN }; @@ -202,7 +202,7 @@ namespace etl template struct type_from_type { - typedef + typedef typename etl::conditional::value, typename T1::type2, typename etl::conditional::value, typename T2::type2, typename etl::conditional::value, typename T3::type2, diff --git a/test/murmurhash3.cpp b/test/murmurhash3.cpp index eb453366..ba4f1443 100644 --- a/test/murmurhash3.cpp +++ b/test/murmurhash3.cpp @@ -7,6 +7,8 @@ // compile and run any of them on any platform, but your performance with the // non-native version will be less than optimal. +#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" + #include "murmurhash3.h" //----------------------------------------------------------------------------- From d3493d601d73d4322caf317b5c6d7c8b1aca0a13 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 25 Feb 2018 13:21:27 +0000 Subject: [PATCH 3/7] Add full set of operators to etl::optional --- library.properties | 2 +- src/optional.h | 271 ++++++++++++++++++++++++++++++++++---- support/Release notes.txt | 5 + test/data.h | 20 +++ test/test_optional.cpp | 155 ++++++++++++++++++++++ 5 files changed, 428 insertions(+), 25 deletions(-) diff --git a/library.properties b/library.properties index 4fe9f709..6da68f3d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=10.20.0 +version=10.21.0 author= John Wellbelove maintainer=John Wellbelove sentence=A C++ template library tailored for embedded systems. diff --git a/src/optional.h b/src/optional.h index f6f4ce10..a1ec6a64 100644 --- a/src/optional.h +++ b/src/optional.h @@ -97,6 +97,7 @@ namespace etl //***************************************************************************** /// An optional type. /// If the optional type is not initialised then a type is not constructed. + /// See http://en.cppreference.com/w/cpp/utility/optional ///\tparam The type to store. ///\ingroup utilities //***************************************************************************** @@ -329,7 +330,7 @@ void swap(etl::optional& lhs, etl::optional& rhs) } //*************************************************************************** -/// Equality operator. +/// Equality operator. cppreference 1 //*************************************************************************** template bool operator ==(const etl::optional& lhs, const etl::optional& rhs) @@ -349,7 +350,16 @@ bool operator ==(const etl::optional& lhs, const etl::optional& rhs) } //*************************************************************************** -/// Less than operator. +/// Equality operator. cppreference 2 +//*************************************************************************** +template +bool operator !=(const etl::optional& lhs, const etl::optional& rhs) +{ + return !(lhs == rhs); +} + +//*************************************************************************** +/// Less than operator. cppreference 3 //*************************************************************************** template bool operator <(const etl::optional& lhs, const etl::optional& rhs) @@ -369,7 +379,67 @@ bool operator <(const etl::optional& lhs, const etl::optional& rhs) } //*************************************************************************** -/// Equality operator. +/// Less than equal operator. cppreference 4 +//*************************************************************************** +template +bool operator <=(const etl::optional& lhs, const etl::optional& rhs) +{ + if (!bool(lhs)) + { + return true; + } + else if (!bool(rhs)) + { + return false; + } + else + { + return lhs.value() <= rhs.value(); + } +} + +//*************************************************************************** +/// greater than operator. cppreference 5 +//*************************************************************************** +template +bool operator >(const etl::optional& lhs, const etl::optional& rhs) +{ + if (!bool(lhs)) + { + return false; + } + else if (!bool(rhs)) + { + return true; + } + else + { + return lhs.value() > rhs.value(); + } +} + +//*************************************************************************** +/// greater than equal operator. cppreference 6 +//*************************************************************************** +template +bool operator >=(const etl::optional& lhs, const etl::optional& rhs) +{ + if (!bool(rhs)) + { + return true; + } + else if (!bool(lhs)) + { + return false; + } + else + { + return lhs.value() >= rhs.value(); + } +} + +//*************************************************************************** +/// Equality operator. cppreference 7 //*************************************************************************** template bool operator ==(const etl::optional& lhs, etl::nullopt_t) @@ -378,25 +448,43 @@ bool operator ==(const etl::optional& lhs, etl::nullopt_t) } //*************************************************************************** -/// Equality operator. +/// Equality operator. cppreference 8 //*************************************************************************** template bool operator ==(etl::nullopt_t, const etl::optional& rhs) +{ + return !bool(rhs); +} + +//*************************************************************************** +/// Inequality operator. cppreference 9 +//*************************************************************************** +template +bool operator !=(const etl::optional& lhs, etl::nullopt_t) +{ + return !(lhs == etl::nullopt); +} + +//*************************************************************************** +/// Inequality operator. cppreference 10 +//*************************************************************************** +template +bool operator !=(etl::nullopt_t , const etl::optional& rhs) +{ + return !(etl::nullopt == rhs); +} + +//*************************************************************************** +/// Less than operator. cppreference 11 +//*************************************************************************** +template +bool operator <(const etl::optional&, etl::nullopt_t) { return false; } //*************************************************************************** -/// Less than operator. -//*************************************************************************** -template -bool operator <(const etl::optional& lhs, etl::nullopt_t) -{ - return !bool(lhs); -} - -//*************************************************************************** -/// Less than operator. +/// Less than operator. cppreference 12 //*************************************************************************** template bool operator <(etl::nullopt_t, const etl::optional& rhs) @@ -405,32 +493,167 @@ bool operator <(etl::nullopt_t, const etl::optional& rhs) } //*************************************************************************** -/// Equality operator. -//************************************************************************** +/// Less than equal operator. cppreference 13 +//*************************************************************************** template -bool operator ==(const etl::optional& lhs, const T& rhs) +bool operator <=(const etl::optional& lhs, etl::nullopt_t) +{ + return !bool(lhs); +} + +//*************************************************************************** +/// Less than equal operator. cppreference 14 +//*************************************************************************** +template +bool operator <=(etl::nullopt_t, const etl::optional&) +{ + return true; +} + +//*************************************************************************** +/// Greater than operator. cppreference 15 +//*************************************************************************** +template +bool operator >(const etl::optional& lhs, etl::nullopt_t) +{ + return bool(lhs); +} + +//*************************************************************************** +/// Greater than operator. cppreference 16 +//*************************************************************************** +template +bool operator >(etl::nullopt_t, const etl::optional&) +{ + return false; +} + +//*************************************************************************** +/// Greater than equal operator. cppreference 17 +//*************************************************************************** +template +bool operator >=(const etl::optional&, etl::nullopt_t) +{ + return true; +} + +//*************************************************************************** +/// Greater than equal operator. cppreference 18 +//*************************************************************************** +template +bool operator >=(etl::nullopt_t, const etl::optional& rhs) +{ + return !bool(rhs); +} + +//*************************************************************************** +/// Equality operator. cppreference 19 +//************************************************************************** +template +bool operator ==(const etl::optional& lhs, const U& rhs) { return bool(lhs) ? lhs.value() == rhs : false; } //*************************************************************************** -/// Equality operator. +/// Inequality operator. cppreference 21 //************************************************************************** -template -bool operator ==(const T& value, const etl::optional& rhs) +template +bool operator !=(const etl::optional& lhs, const U& rhs) { - return bool(rhs) ? rhs.value() == value : false; + return !(lhs == rhs); } //*************************************************************************** -/// Less than operator. +/// Equality operator. cppreference 20 +//************************************************************************** +template +bool operator ==(const U& lhs, const etl::optional& rhs) +{ + return bool(rhs) ? rhs.value() == lhs : false; +} + //*************************************************************************** -template -bool operator <(const etl::optional& lhs, const T& rhs) +/// Inequality operator. cppreference 22 +//************************************************************************** +template +bool operator !=(const U& lhs, const etl::optional& rhs) +{ + return !(lhs == rhs); +} + +//*************************************************************************** +/// Less than operator. cppreference 23 +//*************************************************************************** +template +bool operator <(const etl::optional& lhs, const U& rhs) { return bool(lhs) ? lhs.value() < rhs : true; } +//*************************************************************************** +/// Less than operator. cppreference 24 +//*************************************************************************** +template +bool operator <(const U& lhs, const etl::optional& rhs) +{ + return bool(rhs) ? lhs < rhs.value() : false; +} + +//*************************************************************************** +/// Less than equal operator. cppreference 25 +//*************************************************************************** +template +bool operator <=(const etl::optional& lhs, const U& rhs) +{ + return bool(lhs) ? lhs.value() <= rhs : true; +} + +//*************************************************************************** +/// Less than equal operator. cppreference 26 +//*************************************************************************** +template +bool operator <=(const U& lhs, const etl::optional& rhs) +{ + return bool(rhs) ? lhs <= rhs.value() : false; +} + +//*************************************************************************** +/// Greater than operator. cppreference 27 +//*************************************************************************** +template +bool operator >(const etl::optional& lhs, const U& rhs) +{ + return bool(lhs) ? lhs.value() > rhs : false; +} + +//*************************************************************************** +/// Greater than operator. cppreference 28 +//*************************************************************************** +template +bool operator >(const U& lhs, const etl::optional& rhs) +{ + return bool(rhs) ? lhs > rhs.value() : true; +} + +//*************************************************************************** +/// Greater than equal operator. cppreference 29 +//*************************************************************************** +template +bool operator >=(const etl::optional& lhs, const U& rhs) +{ + return bool(lhs) ? lhs.value() >= rhs : false; +} + +//*************************************************************************** +/// Greater than equal operator. cppreference 30 +//*************************************************************************** +template +bool operator >=(const U& lhs, const etl::optional& rhs) +{ + return bool(rhs) ? lhs >= rhs.value() : true; +} + //*************************************************************************** /// Make an optional. //*************************************************************************** diff --git a/support/Release notes.txt b/support/Release notes.txt index 8a780b79..2dd20638 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,8 @@ +=============================================================================== +10.21.0 +Completion of operator set for etl::optional +Removal of more GCC warnings when using -Wextra. + =============================================================================== 10.20.0 Rewrite of debounce code to factor out commonality. diff --git a/test/data.h b/test/data.h index b66d2f8f..9db25ab4 100644 --- a/test/data.h +++ b/test/data.h @@ -63,6 +63,16 @@ public: return value > other.value; } + bool operator <= (const TestDataDC& other) const + { + return !(value > other.value); + } + + bool operator >= (const TestDataDC& other) const + { + return !(value < other.value); + } + T value; int index; }; @@ -109,6 +119,16 @@ public: return value > other.value; } + bool operator <= (const TestDataNDC& other) const + { + return !(value > other.value); + } + + bool operator >= (const TestDataNDC& other) const + { + return !(value < other.value); + } + T value; int index; }; diff --git a/test/test_optional.cpp b/test/test_optional.cpp index 2c66f275..e0d081f4 100644 --- a/test/test_optional.cpp +++ b/test/test_optional.cpp @@ -114,24 +114,71 @@ namespace etl::optional data2; CHECK(data1 == data2); + CHECK(data2 == data1); data1 = Data("Data1"); CHECK(!(data1 == data2)); + CHECK(!(data2 == data1)); data1 = etl::nullopt; data2 = Data("Data2"); CHECK(!(data1 == data2)); + CHECK(!(data2 == data1)); data1 = Data("Data1"); data2 = Data("Data1"); CHECK(data1 == data2); + CHECK(data2 == data1); data1 = Data("Data1"); data2 = Data("Data2"); CHECK(!(data1 == data2)); + CHECK(!(data2 == data1)); + + CHECK(!(etl::nullopt == data2)); + CHECK(!(data1 == etl::nullopt)); CHECK(data1 == Data("Data1")); CHECK(!(data1 == Data("Data2"))); + CHECK(Data("Data1") == data1); + CHECK(!(Data("Data2") == data1)); + } + + //************************************************************************* + TEST(test_inequality) + { + etl::optional data1; + etl::optional data2; + + CHECK(!(data1 != data2)); + CHECK(!(data2 != data1)); + + data1 = Data("Data1"); + CHECK(data1 != data2); + CHECK(data2 != data1); + + data1 = etl::nullopt; + data2 = Data("Data2"); + CHECK(data1 != data2); + CHECK(data2 != data1); + + data1 = Data("Data1"); + data2 = Data("Data1"); + CHECK(!(data1 != data2)); + CHECK(!(data2 != data1)); + + data1 = Data("Data1"); + data2 = Data("Data2"); + CHECK(data1 != data2); + CHECK(data2 != data1); + + CHECK(etl::nullopt != data2); + CHECK(data1 != etl::nullopt); + + CHECK(!(data1 != Data("Data1"))); + CHECK(data1 != Data("Data2")); + CHECK(!(Data("Data1") != data1)); + CHECK(Data("Data2") != data1); } //************************************************************************* @@ -140,22 +187,130 @@ namespace etl::optional data1; etl::optional data2; + CHECK(!(data2 < data1)); CHECK(!(data1 < data2)); data1 = Data("Data1"); CHECK(!(data1 < data2)); + CHECK(data2 < data1); data1 = etl::nullopt; data2 = Data("Data2"); CHECK(data1 < data2); + CHECK(!(data2 < data2)); data1 = Data("Data1"); data2 = Data("Data2"); CHECK(data1 < data2); CHECK(!(data2 < data1)); + CHECK(etl::nullopt < data2); + CHECK(!(data1 < etl::nullopt)); + CHECK(data1 < Data("Data2")); CHECK(!(data1 < Data("Data1"))); + CHECK(!(Data("Data2") < data1)); + CHECK(Data("Data1") < data2); + } + + //************************************************************************* + TEST(test_less_than_equal) + { + etl::optional data1; + etl::optional data2; + + CHECK(data1 <= data2); + CHECK(data2 <= data1); + + data1 = Data("Data1"); + CHECK(!(data1 <= data2)); + CHECK(data2 <= data1); + + data1 = etl::nullopt; + data2 = Data("Data2"); + CHECK(data1 <= data2); + CHECK(!(data2 <= data1)); + + data1 = Data("Data1"); + data2 = Data("Data2"); + CHECK(data1 <= data2); + CHECK(!(data2 <= data1)); + + CHECK(etl::nullopt <= data2); + CHECK(!(data1 <= etl::nullopt)); + + CHECK(data1 <= Data("Data2")); + CHECK(!(data2 <= Data("Data1"))); + CHECK(data1 <= Data("Data1")); + CHECK(!(Data("Data2") <= data1)); + CHECK(Data("Data1") <= data2); + CHECK(Data("Data1") <= data1); + } + + //************************************************************************* + TEST(test_greater_than) + { + etl::optional data1; + etl::optional data2; + + CHECK(!(data1 > data2)); + CHECK(!(data2 > data1)); + + data1 = Data("Data1"); + CHECK(data1 > data2); + CHECK(!(data2 > data1)); + + data1 = etl::nullopt; + data2 = Data("Data2"); + CHECK(!(data1 > data2)); + CHECK(data2 > data1); + + data1 = Data("Data1"); + data2 = Data("Data2"); + CHECK(data2 > data1); + CHECK(!(data1 > data2)); + + CHECK(!(etl::nullopt > data2)); + CHECK(data1 > etl::nullopt); + + CHECK(!(data1 > Data("Data2"))); + CHECK(data2 > Data("Data1")); + CHECK(Data("Data2") > data1); + CHECK(!(Data("Data1") > data2)); + } + + //************************************************************************* + TEST(test_greater_than_equal) + { + etl::optional data1; + etl::optional data2; + + CHECK(data1 >= data2); + CHECK(data2 >= data1); + + data1 = Data("Data1"); + CHECK(data1 >= data2); + CHECK(!(data2 >= data1)); + + data1 = etl::nullopt; + data2 = Data("Data2"); + CHECK(!(data1 >= data2)); + CHECK(data2 >= data1); + + data1 = Data("Data1"); + data2 = Data("Data2"); + CHECK(!(data1 >= data2)); + CHECK(data2 >= data1); + + CHECK(!(etl::nullopt >= data2)); + CHECK(data1 >= etl::nullopt); + + CHECK(!(data1 >= Data("Data2"))); + CHECK(data2 >= Data("Data1")); + CHECK(data1 >= Data("Data1")); + CHECK(Data("Data2") >= data1); + CHECK(!(Data("Data1") >= data2)); + CHECK(Data("Data1") >= data1); } //************************************************************************* From 1e34b5cf46b7a1c907380d5a6aee678b33d2d066 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 25 Feb 2018 13:41:40 +0000 Subject: [PATCH 4/7] Add #ifdef for GCC pragma --- test/murmurhash3.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/murmurhash3.cpp b/test/murmurhash3.cpp index ba4f1443..39663531 100644 --- a/test/murmurhash3.cpp +++ b/test/murmurhash3.cpp @@ -7,7 +7,11 @@ // compile and run any of them on any platform, but your performance with the // non-native version will be less than optimal. -#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" +#include "platform.h" + +#ifdef ETL_COMPILER_GCC + #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" +#endif #include "murmurhash3.h" From 2872075b1ea94dcd03024ddf77790521249aff18 Mon Sep 17 00:00:00 2001 From: Prasenjit Sengupta Date: Sun, 25 Feb 2018 16:37:13 -0800 Subject: [PATCH 5/7] Remove unused variables in variant.h --- src/variant.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/variant.h b/src/variant.h index 61d8c892..25dcdaba 100644 --- a/src/variant.h +++ b/src/variant.h @@ -643,12 +643,12 @@ namespace etl { public: - TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) + TBase& operator()(uint_least8_t* p_data) { return reinterpret_cast(*p_data); } - const TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) const + const TBase& operator()(uint_least8_t* p_data) const { return reinterpret_cast(*p_data); } From a58d1f58617ce23b286b35c7067a4fd911a124fb Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 26 Feb 2018 21:03:22 +0000 Subject: [PATCH 6/7] Remove variant.h GCC warnings from use of -Wextra --- library.properties | 2 +- src/variant.h | 16 +- support/Release notes.txt | 4 + test/codeblocks/ETL.layout | 1079 ++++++++++++++++++------------------ 4 files changed, 557 insertions(+), 544 deletions(-) diff --git a/library.properties b/library.properties index 6da68f3d..b7dbe69a 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=10.21.0 +version=10.21.1 author= John Wellbelove maintainer=John Wellbelove sentence=A C++ template library tailored for embedded systems. diff --git a/src/variant.h b/src/variant.h index 25dcdaba..429ad708 100644 --- a/src/variant.h +++ b/src/variant.h @@ -643,14 +643,22 @@ namespace etl { public: - TBase& operator()(uint_least8_t* p_data) + TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) { - return reinterpret_cast(*p_data); + switch (typeId) + { + case 0: return reinterpret_cast(*p_data); + default: return reinterpret_cast(*reinterpret_cast(0)); + } } - const TBase& operator()(uint_least8_t* p_data) const + const TBase& operator()(uint_least8_t* p_data, uint_least8_t typeId) const { - return reinterpret_cast(*p_data); + switch (typeId) + { + case 0: return reinterpret_cast(*p_data); + default: return reinterpret_cast(*reinterpret_cast(0)); + } } }; diff --git a/support/Release notes.txt b/support/Release notes.txt index 2dd20638..4e3ecc79 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +10.21.1 +Removal of GCC warnings from variant.h. + =============================================================================== 10.21.0 Completion of operator set for etl::optional diff --git a/test/codeblocks/ETL.layout b/test/codeblocks/ETL.layout index 1306d367..1d941bce 100644 --- a/test/codeblocks/ETL.layout +++ b/test/codeblocks/ETL.layout @@ -1,584 +1,585 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From eee015737241b8fab117ff00e494f90587a72bd5 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 1 Mar 2018 09:14:11 +0000 Subject: [PATCH 7/7] Added version macros --- library.properties | 2 +- src/version.h | 46 ++ support/Release notes.txt | 4 + test/codeblocks/ETL.cbp | 1 + test/codeblocks/ETL.layout | 870 ++++++++++++++++---------------- test/vs2017/etl.vcxproj | 1 + test/vs2017/etl.vcxproj.filters | 3 + 7 files changed, 491 insertions(+), 436 deletions(-) create mode 100644 src/version.h diff --git a/library.properties b/library.properties index b7dbe69a..c9913f89 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=10.21.1 +version=10.21.2 author= John Wellbelove maintainer=John Wellbelove sentence=A C++ template library tailored for embedded systems. diff --git a/src/version.h b/src/version.h new file mode 100644 index 00000000..70f29896 --- /dev/null +++ b/src/version.h @@ -0,0 +1,46 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef __ETL_VERSION__ +#define __ETL_VERSION__ + +#include + +///\defgroup version version +/// Definitions of the ETL version +///\ingroup utilities + +#define ETL_VERSION "10.21.2" +#define ETL_VERSION_MAJOR 10 +#define ETL_VERSION_MINOR 21 +#define ETL_VERSION_PATCH 2 + +#endif + diff --git a/support/Release notes.txt b/support/Release notes.txt index 4e3ecc79..8b7238fd 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +10.21.2 +Added version.h + =============================================================================== 10.21.1 Removal of GCC warnings from variant.h. diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index 279a97cf..9857c6e7 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -208,6 +208,7 @@ + diff --git a/test/codeblocks/ETL.layout b/test/codeblocks/ETL.layout index 1d941bce..ccf9f11d 100644 --- a/test/codeblocks/ETL.layout +++ b/test/codeblocks/ETL.layout @@ -2,159 +2,14 @@ - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -162,109 +17,39 @@ + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - + @@ -272,14 +57,94 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -287,9 +152,129 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -302,14 +287,9 @@ - + - - - - - - + @@ -317,159 +297,19 @@ - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -477,9 +317,44 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -487,39 +362,19 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - + @@ -527,14 +382,9 @@ - + - - - - - - + @@ -542,14 +392,134 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -557,29 +527,59 @@ + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + diff --git a/test/vs2017/etl.vcxproj b/test/vs2017/etl.vcxproj index 46b66b98..5e1be754 100644 --- a/test/vs2017/etl.vcxproj +++ b/test/vs2017/etl.vcxproj @@ -172,6 +172,7 @@ + diff --git a/test/vs2017/etl.vcxproj.filters b/test/vs2017/etl.vcxproj.filters index 77db216e..4f5dbef1 100644 --- a/test/vs2017/etl.vcxproj.filters +++ b/test/vs2017/etl.vcxproj.filters @@ -576,6 +576,9 @@ ETL\Containers\Generators + + ETL\Utilities +