--- 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 #8216;bool isEqual(const A, const B) [with A =
std::mapint, int, B = std::mapint, double]#8217;:
template2.cc:16:4: instantiated from #8216;void isTrue(const A, const B)
[with A = std::mapint, int, B = std::mapint, double]#8217;
template2.cc:53:17: instantiated from here
template2.cc:6:17: error: no match for #8216;operator==#8217; in #8216;aA ==
aB#8217;
[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::mapKey,Value1 const aA, std::mapKey,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::mapKey,Value1 const aA, std::mapKey,Value2 const aB)
{
if (aA.size() != aB.size()) return false;
for (typename std::mapKey,Value1::const_iterator it1 = aA.begin();
it1 != aA.end(); ++it1)
{
typename std::mapKey,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::mapint, int ma;
std::mapint, double mb;
isTrue(ma, mb); // Error here
return 0;
}
[/Code]
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42281