I want to test if a non-empty vector contains identical elements. Is this the best way?
count(vecSamples.begin()+1, vecSamples.end(), vecSamples.front()) == vecSamples.size()-1;
Comparing two vectors using operator == std::vector provides an equality comparison operator==, it can be used to compare the contents of two vectors. For each element in the vector it will call operator == on the elements for comparisons.
R – all() function all() function in R Language will check in a vector whether all the values are true or not.
setequal() function in R Language is used to check if two objects are equal. This function takes two objects like Vectors, dataframes, etc. as arguments and results in TRUE or FALSE, if the Objects are equal or not.
For two vectors to be equal, they must have both the magnitude and the directions equal.
In c++11 (or Boost Algorithm)
std::all_of(vecSamples.begin()+1,vecSamples.end(),
[&](const T & r) {return r==vecSamples.front();})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With