Add operator<< for source_location

This commit is contained in:
Peter Dimov
2020-01-21 01:52:41 +02:00
parent e4ae80770f
commit e52b379928
3 changed files with 55 additions and 0 deletions
+24
View File
@@ -10,6 +10,7 @@
#include <boost/current_function.hpp>
#include <boost/config.hpp>
#include <boost/cstdint.hpp>
#include <iosfwd>
namespace boost
{
@@ -54,6 +55,29 @@ public:
}
};
template<class E, class T> std::basic_ostream<E, T> & operator<<( std::basic_ostream<E, T> & os, source_location const & loc )
{
os.width( 0 );
if( loc.line() == 0 )
{
os << "(unknown source location)";
}
else
{
os << loc.file_name() << ':' << loc.line();
if( loc.column() )
{
os << ':' << loc.column();
}
os << ": in function '" << loc.function_name() << '\'';
}
return os;
}
} // namespace boost
#if defined( BOOST_DISABLE_CURRENT_LOCATION )