C++ 检查同一列表元素是否包含true或false
假设我有一个列表,如下所示:C++ 检查同一列表元素是否包含true或false,c++,C++,假设我有一个列表,如下所示: ID Valid -------------- 1000 true 1000 false 1000 true 2000 false 2000 false 3000 true 3000 true 这个布尔值来自一个函数boolisexpired(MyClass&a) 如何检查一组元素是否具有相同或不同的布尔值? 例如,在本例中,1000应该为false,因为列表中的第二个1000的值为false 这是假的 1000
ID Valid
--------------
1000 true
1000 false
1000 true
2000 false
2000 false
3000 true
3000 true
这个布尔值来自一个函数boolisexpired(MyClass&a)
如何检查一组元素是否具有相同或不同的布尔值?
例如,在本例中,1000应该为false,因为列表中的第二个1000的值为false
这是假的
1000 true
1000 false //because of this
1000 true
2000 false
2000 false
这是假的
1000 true
1000 false //because of this
1000 true
2000 false
2000 false
这是真的
3000 true
3000 true
我试图创建一个新的映射,它将覆盖键和值
std::map<long, bool> status;
for(const auto &it : myList)
{
status[it.ID] = status[it.ID] || isExpired(it);
}
std::地图状态;
for(const auto&it:myList)
{
状态[it.ID]=状态[it.ID]| | isExpired(it);
}
但它并没有像预期的那样起作用。对于ID为1000的元素,它返回
true
。如果不想使用|
,则要使用&
,这意味着必须默认为true:
std::地图状态;
for(const auto&it:myList)
{
自动输入=status.find(it.ID);
if(entry!=status.end()){
条目->第二条=条目->第二条和第三条(it);
}否则{
状态[it.ID]=true;
}
}