升压日志问题,版本1.59

时间:2015-08-24 15:16:38

标签: 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;
}

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

  

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

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

1 个答案:

答案 0 :(得分:4)

Live version 看起来问题在enable_if_formatting_ostream结构中。它被添加到this commit中。看起来像

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; };

现在operator <<

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

之前

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)

并且record_ostream派生自formatting_ostream编译器可以找到重载,但现在没有,因为使用SFINAE并且struct仅在使用type时才有formatting_ostream typedef 。 this可以解决此问题。

相关问题