Can I check in C(++) if an array is all 0 (or false)?
问题 Can I check in C(++) if an array is all 0 (or false) without iterating/looping over every single value and without allocating a new array of the same size (to use memcmp )? I'm abusing an array of bools to have arbitrary large bitsets at runtime and do some bitflipping on it 回答1: You can use the following condition: (myvector.end() == std::find(myvector.begin(), myvector.end(), true)) Obviously, internally, this loops over all values. The alternative (which really should avoid looping) is to