【问题标题】:Problems with boost log, version 1.59升压日志问题,版本 1.59
【发布时间】:2015-08-24 15:16:37
【问题描述】:

以下代码在 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 错误信息是:

error: no match for ‘operator

文档和发行说明都没有记录需要更改的内容。

【问题讨论】:

标签: c++ logging boost boost-log


【解决方案1】:

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 &lt;&lt;

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 并且只有在使用formatting_ostream 时结构才会有type typedef。而this 可以解决这种情况。

【讨论】:

猜你喜欢
  • 2016-04-16
  • 1970-01-01
  • 2021-03-12
  • 2014-09-14
  • 2019-02-16
  • 2011-01-03
  • 1970-01-01
  • 1970-01-01
  • 2012-02-20
相关资源
最近更新 更多