Can I check C (++) if the array is 0 (or false)?

Is it possible to check C (++) if the array is 0 (or false) without repeating / looping over each individual value and without allocating a new array of the same size (for use memcmp)?

I am abusing the bools array to have arbitrary large bits at runtime and do some bitfling on it

+5
source share
8 answers

You can use the following condition:

(myvector.end() == std::find(myvector.begin(), myvector.end(), true))

Obviously, internally this happens for all meanings.

( ) , true - .

UPDATE

, .

+4

, . ? , , 0 ! memcmp, , . , .

, , -0.

- SIMD ( , ), .

(Btw, , C/++. , , .)

+2

, , , (, ) . , , ++ , c.

+1

boost::dynamic_bitset. none std::bitset - , ​​ .

+1

, N, .

, 15- , .

8- , 4- , 2- 1- .

, , . , ( , ).

8- , 4- 8 .

+1

, memcmp, .

, ++, .

0

, .

- , - , , bool (__int64 say), .

EDIT: , . , ++ ..

0

knittl,

I do not assume that you have access to some fancy DMA hardware on the target computer? Sometimes DMA hardware supports exactly the required operation, i.e. "Is this memory area zero?" This hardware acceleration comparison is a common solution when working with large bit buffers. For example, some RAID controllers use this mechanism to check for parity.

0
source

All Articles