Check if all the array members have the same value

algorithm, c++

Solution

Keep a counter and add/subtract as the flags flip true or false. Then `if ctr == numOfBools` or `ctr == 0` they are all the same.

Edit: Should have added that you need checks so you don't subtract if the bool is already off or add if it is already on.

Problem

Is there an STL algorithm or fast technique to test if all the members of an array are set to the same value? For example, I have an array with default values: ``` bool *finishFlags =new (std::nothrow) bool[numOfBools]; //Init all to false: for(int i = 0 ; i < numOfBools; ++i){ *finishFlags++ = false; } ``` Now, during the runtime some of the array members are set to true and I want to test if all of them are set to the same value( true in this case).Is there a fast way of doing it without typical array iteration?

Original source