gpt4 book ai didi

c++ - boost 日志问题,版本 1.59

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:37:17 25 4
gpt4 key购买 nike

以下代码在 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<<’ (operand types are ‘boost::log::v2s_mt_posix::basic_record_ostream’ and ‘Foo’)

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

最佳答案

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 并且结构将具有 type仅在 formatting_ostream 时使用 typedef用来。和 this可以解决这种情况。

关于c++ - boost 日志问题,版本 1.59,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32185858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com