I have a function called 'equal' that takes 2 parameters, each of which must be either std :: set or std :: multiset, and the type of the container element must be arithmetic (int, float, double ...). I want the compiler to report an error if the above 2 conditions are not satisfied.
Hope my code can work as follows:
int main(void)
{
std::set<int> s1;
std::set<int> s2;
equal(s1, s2);
std::multiset<float> s3;
std::multiset<float> s4;
equal(s3, s4);
std::set<int> s5;
std::multiset<int> s6;
equal(s5, s6);
std::set<int*> s7;
std::set<int*> s8;
equal(s7, s8);
std::vector<int> s9;
std::vector<int> s10;
equal(s9, s10);
return 0;
}
And now he can check if the element is an arithmetic type, as shown below:
template <class Container, class = typename std::enable_if<std::is_arithmetic<typename Container::value_type>::value>::type>
bool equal(const Container &container1, const Container &container2)
{
return true;
}
But how to make sure that the container is installed or multi-network?
the compiler can support C ++ 11, for example vc2015 or gcc4.8