Does anybody know why the next piece of code isn't compiled on Clang 4.0.1?
I have the next error:
call to function 'operator<<' that is neither visible in the template definition nor found by argument-dependent lookup
There is some file test.cpp
#include <vector>
#include <iostream>
namespace Wrapper
{
template<typename T>
struct QuotedStringImpl
{
T const& Value;
explicit QuotedStringImpl(T const& value) :
Value(value)
{
}
};
template<typename T>
inline std::ostream& operator <<(std::ostream& stream, QuotedStringImpl<T> const& rhs)
{
return stream << rhs.Value;
}
template<>
inline std::ostream& operator <<(std::ostream& stream, QuotedStringImpl<std::string> const& rhs)
{
return stream << '"' << rhs.Value << '"';
}
template<typename T>
inline QuotedStringImpl<T> QuotedString(T const& value)
{
return QuotedStringImpl<T>(value);
}
template<typename T>
inline std::ostream& operator <<(std::ostream& stream, std::vector<T> const& value)
{
stream << "[";
std::copy(value.begin(), value.end(), std::ostream_iterator<T>(stream, ", "));
stream << "]";
return stream;
}
} // namespace Wrapper
namespace
{
struct Struct
{
};
std::ostream& operator<<(std::ostream& stream, Struct const&)
{
return stream << "(struct value)";
}
} // namespace
int main()
{
std::vector<Struct> collection(2);
std::cout << Wrapper::QuotedString(collection);
}
This code is successfully compiled with msvc 15. But I have troubles with Clang 4.0.1. According with this documentation ADL should be applied in place of instantiation. But it doesn't work for me. What is the reason of such behaviour?