------- Comment #2 from jezz at hkfree dot org 2009-12-04 21:30 ------- I have tried to simplify the code, but I have created only problem with int (not with user structure). In real code we have also something like this:
Tested with same compilers: template2.cc: In function ‘bool isEqual(const A&, const B&) [with A = std::map<int, int>, B = std::map<int, double>]’: template2.cc:16:4: instantiated from ‘void isTrue(const A&, const B&) [with A = std::map<int, int>, B = std::map<int, double>]’ template2.cc:53:17: instantiated from here template2.cc:6:17: error: no match for ‘operator==’ in ‘aA == aB’ [Code] #include <map> template <typename A, typename B> bool isEqual(A const &aA, B const &aB) { return aA == aB; } // Forward declaration works //template <typename Key, typename Value1, typename Value2> //bool isEqual(std::map<Key,Value1> const &aA, std::map<Key,Value2> const &aB); template <typename A, typename B> inline void isTrue(A const &aA, B const &aB) { if (not isEqual(aA, aB)) throw new std::exception(); } template <typename A, typename B> void isFalse(A const &aA, B const &aB) { if (isEqual(aA, aB)) throw new std::exception(); } template <typename Key, typename Value1, typename Value2> bool isEqual(std::map<Key,Value1> const &aA, std::map<Key,Value2> const &aB) { if (aA.size() != aB.size()) return false; for (typename std::map<Key,Value1>::const_iterator it1 = aA.begin(); it1 != aA.end(); ++it1) { typename std::map<Key,Value2>::const_iterator it2 = aB.find(it1->first); if (it2 == aB.end() or it1->second != it2->second) return false; } return true; } int main(int argc, char *argv[]) { isTrue(1, 1); double da, db; da = 1.0; db = 2.0; isFalse(da, db); isTrue(da, 1); std::map<int, int> ma; std::map<int, double> mb; isTrue(ma, mb); // Error here return 0; } [/Code] -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42281