【问题标题】:Possible implementations of std::ignorestd::ignore 的可能实现
【发布时间】:2015-09-28 11:40:06
【问题描述】:

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

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

namespace std {

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

const _Ignore ignore = _Ignore ();

} // namespace std

还有关于这些问题的进一步讨论。那么,当前的实现是什么样的呢?为什么?

【问题讨论】:

  • 什么不清楚,有什么问题?
  • 执行选择,看看他们做了什么。

标签: c++ c++11


【解决方案1】:

在 GCC 中,它看起来像您发布的内容,只是 ignore 不是 const。这克服了您链接的线程中看起来主要的反对意见。

在 Clang 中赋值运算符是 const,也返回 const,整个类本身就是一个模板(除了赋值运算符是一个模板)。无论出于何种原因,模板实例化都使用unsigned char

【讨论】:

    猜你喜欢
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 2018-11-26
    • 2013-05-19
    • 2022-10-23
    • 2016-03-05
    • 2014-04-04
    • 2023-04-08
    相关资源
    最近更新 更多