While implementing a simple logger
struct DebugOutput {
DebugOutput(std::ostream& out = std::cerr) : m_Out(out) {}
template<typename T>
inline DebugOutput& operator <<(T&& value) {
m_Out << value;
return *this;
}
private:
std::ostream& m_Out;
};
I found out std::endl
wouldn't be captured by the universal reference.
DebugOutput dbg;
dgb << std::endl;
I found this this post which explains you need to add an overloaded function within the structure which takes specifically the function pointer signature, ie :
typedef std::ostream& (*StandardEndLine)(std::ostream&);
inline DebugOutput& operator<<(StandardEndLine manip) {
return *this;
}
Why the function pointer is not captured by the universal reference ? Isn't it a type as int
or void*
?