Move `vtkm::Vec` operators from gloabal to `vtkm` namespace
Having the operators in the global namespace has name lookup issues. Please refer to the following for example (try it on godbolt):
#include <string>
#include <vector>
#include <iostream>
namespace vtkm
{
template<typename T, int S>
struct Vec
{
const T& operator[](int i) const { return m_data[i]; }
T m_data[S];
};
// // vtkm overload namespace
// template <typename T, int Size>
// std::ostream& operator<<(std::ostream& stream, const vtkm::Vec<T, Size>& vec)
// {
// stream << "[";
// for (int component = 0; component < Size - 1; component++)
// {
// stream << vec[component] << ",";
// }
// return stream << vec[Size - 1] << "]";
// }
} // vtkm
// global namespace
template <typename T, int Size>
std::ostream& operator<<(std::ostream& stream, const vtkm::Vec<T, Size>& vec)
{
stream << "[";
for (int component = 0; component < Size - 1; component++)
{
stream << vec[component] << ",";
}
return stream << vec[Size - 1] << "]";
}
namespace vtkm
{
namespace internal
{
class A {};
// this hides the global operator << for any use inside vtkm::internal namespace.
std::ostream& operator<<(std::ostream& stream, A a)
{
return stream;
}
}
}
namespace vtkm
{
namespace internal
{
namespace mine
{
void test_namespace_lookup()
{
vtkm::Vec<float, 4> vec;
std::cout << vec << std::endl;
}
}
}
}
int main()
{
vtkm::internal::mine::test_namespace_lookup();
vtkm::Vec<float, 4> vec;
std::cout << vec << std::endl;
}
Moving the operator to the vtkm
will enable ADL.