design quesiton

I was given a problem to design a function to compare two maps and see if they are equal. The value type of the maps can be primitive types like int, float etc. or containers like vector, array, or map. Here is what I get so far:
template <typename T> bool equal(T&a, T&b){
cout<<"compare nonmap"<<endl;
return a==b;
}

template <typename T> bool equal(map<string,T> &a,map<string,T> &b){
cout<<"compare maps"<<endl;
if (a.size()!=b.size()) return false;
typename map<string,T>::iterator ita;
typename map<string,T>::iterator itb;
for(ita=a.begin();ita!=a.end();ita++){
itb=b.find(ita->first);
if (itb==b.end()) return false;
if (!equal(ita->second,itb->second)) return false;
}
return true;
}

this works fine for maps of maps or maps of primitive types. My question is what to do with maps of vectors? Do I need to write a separate template function for vector, array and other containers? What should be the best design?
No. I'd say it's reasonable to assume/assert there's an equality test on keys/values.
To kbw's point, you can use concept checks for this.

http://www.boost.org/doc/libs/1_42_0/libs/concept_check/using_concept_check.htm

Just require that the value types are EqualityComparable.

In the future, please use code tags when posting code.
Why not increment both iterators each loop rather than calling find?
Thanks guys for the input. I am also looking at the stl_map.h
@moorecm If increment iterator of a map, are the keys visited in an order?
find may be necessary if you can specify different sort predicates for two maps that have the same key/value types.
Both std::vector and std::map already have operator== defined that does the right
thing as long as the contained types are homogeneous...
Topic archived. No new replies allowed.