1

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 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?

g-217
  • 2,069
  • 18
  • 33

1 Answers1

2

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.

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.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436