Skip to content

Instantly share code, notes, and snippets.

@arnobaer
Created November 30, 2017 17:38
Show Gist options
  • Save arnobaer/6057a8c1337c59181bbafe8e2a7e1407 to your computer and use it in GitHub Desktop.
Save arnobaer/6057a8c1337c59181bbafe8e2a7e1407 to your computer and use it in GitHub Desktop.
c++ test if all items in an iteratable container are equal
#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