From 784ba67b9ddfab853a61ccab96648707f3fd8f88 Mon Sep 17 00:00:00 2001 From: Stephen Cprek Date: Mon, 25 Sep 2017 12:49:21 -0500 Subject: Add std::map operator== overload and != for vector Change-Id: I3b40533d2586d455db184e9d845618b41b848296 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/46712 Tested-by: Jenkins Server Tested-by: FSP CI Jenkins Reviewed-by: Nicholas E. Bofferding Tested-by: Jenkins OP Build CI Tested-by: Jenkins OP HW Reviewed-by: Michael Baiocchi Reviewed-by: Marshall J. Wilks Reviewed-by: Daniel M. Crowell --- src/include/map | 28 ++++++++++++++++++++++++++++ src/include/vector | 8 +++++++- 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'src/include') diff --git a/src/include/map b/src/include/map index ddfa17ea7..75e710163 100644 --- a/src/include/map +++ b/src/include/map @@ -473,6 +473,34 @@ namespace std equal_range( const key_type& k) const { return submap::equal_range(k); } }; + + /** + * @brief Map equality comparison. + * @param lhs A map. + * @param rhs A map of the same type as lhs. + * @return True iff the size and elements of the maps are equal. + * + * This is an equivalence relation. It is linear in the size of the + * maps. Maps are considered equivalent if their sizes are equal, + * and if corresponding elements compare equal. + */ + template + inline bool operator==(const map<_K,_T,_C>& lhs, + const map<_K,_T,_C>& rhs) + { + return (lhs.size() == rhs.size()) && + (std::equal(lhs.begin(), lhs.end(), rhs.begin())); + } + + /** + * @brief Map inequality comparison. See operator== + */ + template + inline bool operator!=(const map<_K,_T,_C>& lhs, + const map<_K,_T,_C>& rhs) + { + return !(lhs == rhs); + } }; #endif diff --git a/src/include/vector b/src/include/vector index ac502a047..198d086cb 100644 --- a/src/include/vector +++ b/src/include/vector @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2011,2016 */ +/* Contributors Listed Below - COPYRIGHT 2011,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -730,6 +730,12 @@ namespace std return true; } + template + bool operator!=(const vector& l, const vector& r) + { + return !(l == r); + } + }; // end namespace std // ------------------------------------------------------------------------------------------------ -- cgit v1.2.1