我有以下数据结构:for循环 - 遍历特定元素
struct T
{
std::string name;
bool active;
};
然后我想遍历T的载体,但只针对有源元件:
std::vector<T> myVector;
//fill vector
for(const auto& item: myVector)
{
if(!item.active)
{
continue;
}
//do something;
}
有任何允许在不使用if和/或continue语句的情况下实现的功能?
不需要我填写评论 –
根据你的要求,你似乎并不需要“主动”成员开始。 – NiVeR
反转条件,在“if”里面“做点什么”? –