std :: ignore的可能实现 [英] Possible implementations of std::ignore

查看:200
本文介绍了std :: ignore的可能实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试搜索std :: ignore的可能实现,但未能找到清楚的答案。

I tried searching for possible implementations of std::ignore, but failed to find a clear answer.

http://mail-archives.apache.org/mod_mbox/stdcxx-dev/ 200807.mbox/%3C4872AA41.7040005@roguewave.com%3E 引用了c ++规范的问题,并提供和说明性实现为

http://mail-archives.apache.org/mod_mbox/stdcxx-dev/200807.mbox/%3C4872AA41.7040005@roguewave.com%3E cites problems with c++ spec and provides and illustrative implementation as

namespace std {

struct _Ignore
{
    template <class _Type>
    _Ignore& operator= (const _Type& value) { return *this; }
};

const _Ignore ignore = _Ignore ();

} // namespace std

。那么,当前的实现如何?为什么?

And there are further discussions about the problems. So, how the current implementations looks like? and why?

推荐答案

在GCC中它看起来像你发布的除了 ignore 不是 const 。这会克服什么看起来是你链接的线程的主要目标。

In GCC it looks like what you posted except that ignore is not const. That overcomes what looks to be the primary objection in the thread you linked.

在Clang中,赋值运算符是const,并且返回const,整个类本身是一个模板(除了作为模板的赋值运算符之外)。模板实例化由于任何原因使用 unsigned char

In Clang the assignment operator is const, and also returns const, and the entire class is itself a template (in addition to the assignment operator being a template). The template instantiation uses unsigned char for whatever reason.

这篇关于std :: ignore的可能实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆