std :: ignore的要求 [英] Requirements for std::ignore
问题描述
C ++ 11引入了一个名为 std :: ignore
的对象:
C++11 introduces an object called std::ignore
:
const /* unspecified */ ignore;
为了简洁,让
typedef decltype(std::ignore) T;
从我可以知道, T
是因为 std :: tie
的规定,它是 CopyAssignable
20.4.2.4:7]。
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].
在g ++ - 4.8中,我发现 T
是另外 DefaultConstructible
(例如, T x;
编译)。这是实现定义的行为吗?
In g++-4.8, I find that T
is additionally DefaultConstructible
(e.g., T x;
compiles). Is this implementation-defined behavior?
(如果对 T
有其他要求, 。)
(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.
无论标准库容器允许 ignore
与 tie
配合使用时,可获得所需的行为。图书馆 可以为其提供模板< T&> operator =(const T&)
overload,或者可以使用一些其他机制使其工作。标准没有说。因此,它甚至不需要 CopyAssignable
。
Whatever machinery that a standard library container does to allow ignore
to gain the required behavior when used with tie
is up to that standard library implementation. The library may give it a template<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 be CopyAssignable
.
注意 tie
只有特殊的行为,如果你特别使用
忽略
。如果你使用一些其他值,你自己创建(因为类型没有要求,你不能保证能够做),你会得到未定义的行为。
Note that tie
only has special behavior if you specifically use ignore
. 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.
这篇关于std :: ignore的要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!