[英]C++ How affects mutable keyword to the performance of container?
I want to know how mutable affects a container (map, vector, list, ...). 我想知道mutable如何影响容器(map,vector,list,...)。 In addition, what do I have to bear in mind?
另外,我还要记住什么?
mutable
, like const
, is just a compile-time thing. 像
const
一样, mutable
只是一个编译时间的东西。 It just allows you to modify that variable in a constant context. 它只允许您在常量上下文中修改该变量。 At runtime, there is no difference wether you declared the container
mutable
or not. 在运行时,您宣布容器是否
mutable
是没有区别的。
class Foo{
mutable int i;
public:
void foo() const{
// constant context, but you can modify `i`
i = 5;
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.