升压日志问题,版本1.59

Mar*_*s V 6 c++ logging boost boost-log

以下代码与boost 1.57一样正常工作:

#include <iostream>
#include <boost/log/trivial.hpp>

struct Foo
{
    int d=1;
};

std::ostream& operator<<(std::ostream& out, const Foo& foo)
{
    out << "Foo: " << foo.d;
    return out;
}

int main()
{
    BOOST_LOG_TRIVIAL(info) << Foo();
    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

使用boost 1.59相同的代码失败.第一个gcc错误消息是:

错误:'operator <<'不匹配(操作数类型为'boost :: log :: v2s_mt_posix :: basic_record_ostream'和'Foo')

文档和发行说明均未记录需要更改的内容.

For*_*veR 4

实时版本 看起来问题出在enable_if_formatting_ostream结构中。它已添加到此提交中。看起来像

template< typename StreamT, typename R >
struct enable_if_formatting_ostream {};
template< typename CharT, typename TraitsT, typename AllocatorT, typename R >
struct enable_if_formatting_ostream< basic_formatting_ostream< CharT, TraitsT, AllocatorT >, R > { typedef R type; };
Run Code Online (Sandbox Code Playgroud)

现在operator <<

template< typename StreamT, typename T >
inline typename boost::log::aux::enable_if_formatting_ostream< StreamT, StreamT& >::type
operator<< (StreamT& strm, T const& value)
Run Code Online (Sandbox Code Playgroud)

之前是

template< typename CharT, typename TraitsT, typename AllocatorT, typename T >
inline basic_formatting_ostream< CharT, TraitsT, AllocatorT >&
operator<< (basic_formatting_ostream< CharT, TraitsT, AllocatorT >& strm, T const& value)
Run Code Online (Sandbox Code Playgroud)

因为record_ostream从编译器派生可以找到重载,但现在不能,因为使用了 SFINAE 并且 struct仅在使用时才formatting_ostream会有typedef。这可以解决这种情况typeformatting_ostream

  • 查看 boost trac 后,记录并修复了此错误:https://svn.boost.org/trac/boost/ticket/11549 (3认同)