C++ 'using': Should I use it or should I avoid it?
- by Mehrdad
I realize there are subtly different semantics for some of these, because of ADL.
In general, though: Which one should I prefer (if any), and why?
(Or does it depend on the situation (e.g. inline header vs. implementation?)
Also: should I prefer ::std:: over std::?
using namespace std;
pair<string::const_iterator, string::const_iterator> f(const string &s)
{
return make_pair(s.begin(), s.end());
}
or
std::pair<std::string::const_iterator, std::string::const_iterator> f(const std::string &s)
{
return std::make_pair(s.begin(), s.end());
}
or
using std::pair;
using std::string;
pair<string::const_iterator, string::const_iterator> f(const string &s)
{
return make_pair(s.begin(), s.end());
}
or
std::pair<std::string::const_iterator, std::string::const_iterator> f(const std::string &s)
{
using std::make_pair;
return make_pair(s.begin(), s.end());
}
or
std::pair<std::string::const_iterator, std::string::const_iterator> f(const std::string &s)
{
using namespace std;
return make_pair(s.begin(), s.end());
}
or something else?
(This is assuming I don't have C++11 and auto.)