Sunday, 25 August 2013

Check if all the array members have the same value

Check if all the array members have the same value

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?

No comments:

Post a Comment