Created
November 30, 2017 17:38
-
-
Save arnobaer/6057a8c1337c59181bbafe8e2a7e1407 to your computer and use it in GitHub Desktop.
c++ test if all items in an iteratable container are equal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
template<typename T> | |
bool all_equal(const T& c) | |
{ | |
return c.empty() or std::equal(++c.begin(), c.end(), c.begin()); | |
} | |
// Example: | |
// std::vector<int> v{42, 42, 42}; | |
// all_equal(v); // returns true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment