C++11 introduces an object called std::ignore
:
const /* unspecified */ ignore;
For brevity, let
typedef decltype(std::ignore) T;
From what I can tell, the only requirement for T
is that it is CopyAssignable
, due to the specification of std::tie
[C++11, 20.4.2.4:7].
In g++-4.8, I find that T
is additionally DefaultConstructible
(e.g., T x;
compiles). Is this implementation-defined behavior?
(If there are other requirements on T
that I have missed, please elaborate.)
The standard has no requirements on the type of
ignore
, besides the fact that it is a type that is distinct from all other types.Whatever machinery that a standard library container does to allow
ignore
to gain the required behavior when used withtie
is up to that standard library implementation. The library may give it atemplate<T&> operator=(const T&)
overload, or it may use some other mechanism to make it work. The standard doesn't say. So it doesn't even have to beCopyAssignable
.Note that
tie
only has special behavior if you specifically useignore
. If you use some other value, created by yourself (which, since the type has no requirements, you are not guaranteed to be able to do), you will get undefined behavior.Formally, I don't think there is any requirement at all being placed. The fact that
tie()
can acceptignore
as an argument does not mean that it has to store a value of that type in the tuple: although that's most likely what's going to happen in practice, I do not see this as being necessarily implied by the formal specification.No, the behavior is unspecified, since the implementation is not required to document it (thanks to Pete Becker for clarifying this point).