The following very simple code won't compile
#include <vector>
#include <string>
namespace Foobar {
struct Test {
std::string f;
std::uint16_t uuid;
};
}
bool operator==(const Foobar::Test& lhs, const Foobar::Test& rhs){
return lhs.f == rhs.f && lhs.uuid == rhs.uuid;
}
int main(){
std::vector<Foobar::Test> a;
std::vector<Foobar::Test> b;
if(a==b){
}
return 0;
}
Won't compile in any of the compilers I have.
While the following
#include <vector>
#include <string>
namespace Foobar {
struct Test {
std::string f;
std::uint16_t uuid;
};
bool operator==(const Foobar::Test& lhs, const Foobar::Test& rhs){
return lhs.f == rhs.f && lhs.uuid == rhs.uuid;
}
}
int main(){
std::vector<Foobar::Test> a;
std::vector<Foobar::Test> b;
if(a==b){
}
return 0;
}
Compiles just fine, which makes me think std::vector<T>
comparison operator looks in the namespace of T
, why won't it consider the global namespace?