Enable template only if the return expression is valid
问题 I want to write a wrapper over std::ostream in this style: #include <iostream> struct OstreamWrapper { OstreamWrapper(std::ostream &out) : out(out) {} template< typename T > decltype(auto) operator<<(T &&arg) { return out << std::move< T >(arg); } std::ostream &out; }; int main() { OstreamWrapper wrap(std::cout); wrap << "Hello, world!"; // This works wrap << std::endl; // This does not work return 0; } The problem with this approach is that it does not work (for example) with std::endl ,