我有以下數據結構: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」裏面「做點什麼」? –