I want to compare two vectors using template class.
vector<Msg> gExpMsg;
vector<Msg> gRevcMsg;
i have to use template class;
and compare 2 vector
using memcmp
.
Could you please guide me in code C++.
Thanks in Advance.
I want to compare two vectors using template class.
vector<Msg> gExpMsg;
vector<Msg> gRevcMsg;
i have to use template class;
and compare 2 vector
using memcmp
.
Could you please guide me in code C++.
Thanks in Advance.
You can use STL equal or mismatch algorithms to compare two containers. In these algorithms you can give your own predicate functor if you want. Below is the link where you can find sample code mismatch algorithm sample
mismatch returns the pair values which holds the differences between two containers (in your case its vector) Here is some snippet from sample for quick view
//find first mismatch
pair<vector<int>::iterator,list<int>::iterator> values;
values = mismatch (coll1.begin(), coll1.end(), //first range
coll2.begin()); //second range
if (values.first == coll1.end())
cout <<"no mismatch"<<endl;
else
cout <<"first mismatch: "<<*values.first<<" and "<<*values.second<<endl;
With predicate
values = mismatch (coll1.begin(), coll1.end(), //first range
col12. begin(), //second range
less_equal<int>() ) //criterion
if (values.first == coll1.end())
cout <<"always less-or-equal"<<endl;
else
cout <<"not less-or-equal: "<<*values.first<<" and "
<<*values.second<<endl;