diff --git a/src/build/tools/addCopyright b/src/build/tools/addCopyright index 5e1c9216c84..22453d551cd 100755 --- a/src/build/tools/addCopyright +++ b/src/build/tools/addCopyright @@ -572,16 +572,24 @@ sub filetype if ( -f $filename ) { my $type = `grep "\\\$Filetype:.*\\\$" $filename`; - if ( $type =~ m/\$Filetype:([^\$]*)\$/ ) + if ($type ne "") { - $type = $1; + if ( $type =~ m/\$Filetype:([^\$]*)\$/ ) + { + $type = $1; + } + $type =~ s/^\s*//; + $type =~ s/\s*$//; + my @knownTypes = qw/ Assembly Automake Autoconf C CVS EmxFile + LinkerScript Makefile MofFile Perl PrdRuleFile + PrdTestCaseFile Python RPC Shellscript Tcl /; + return $type if ( grep(/^$type$/, @knownTypes) ); + } + # Search for files that have the comment /* vim: set filetype=cpp : */ + elsif (`grep \"set filetype=cpp\" $filename`) + { + return "C"; } - $type =~ s/^\s*//; - $type =~ s/\s*$//; - my @knownTypes = qw/ Assembly Automake Autoconf C CVS EmxFile - LinkerScript Makefile MofFile Perl PrdRuleFile - PrdTestCaseFile Python RPC Shellscript Tcl /; - return $type if ( grep(/^$type$/, @knownTypes) ); } { # Other random files containing non-printable characters. my $file = `cat $filename`; diff --git a/src/include/map b/src/include/map index ddfa17ea716..75e71016318 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 ac502a04731..198d086cb2a 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 // ------------------------------------------------------------------------------------------------ diff --git a/src/usr/testcore/lib/stltest.H b/src/usr/testcore/lib/stltest.H index c16354ff39c..31cc3cbe976 100644 --- a/src/usr/testcore/lib/stltest.H +++ b/src/usr/testcore/lib/stltest.H @@ -233,6 +233,30 @@ class STLTest : public CxxTest::TestSuite } + // Test map comparison with non-integral key,value pairs + std::map, std::vector > m1 = { + { {1,2,3}, {100, 101, 102} }, + { {4,5,6}, {103, 104, 105} }, + { {7,8,9}, {106, 107, 108} }, + { {10,11,12}, {109, 110, 111} }, + }; + std::map, std::vector > m2 = { + { {10,11,12}, {109, 110, 111} }, + { {7,8,9}, {106, 107, 108} }, + { {4,5,6}, {103, 104, 105} }, + { {1,2,3}, {100, 101, 102} }, + }; + + if (m1 != m2) + { + TS_FAIL("std::map operator!= is true on equal maps"); + } + m2.at({1,2,3}).at(0) = 99; + if (m1 == m2) + { + TS_FAIL("std::map operator== is true on unequal maps"); + } + }