vector< vector >: verify that all have equal sizes

algorithm, c++, vector

Solution

How about

#include <algorithm> // for std::all_of

auto const required_size = lines.front().size();
std::all_of(begin(lines), end(lines),
    [required_size](const Line& x){ return x.size() == required_size; });

Won't work for empty lists, unfortunately and you have to get the required size into the predicate somehow.

Problem

Is there an std/boost algorithm to verify that all vectors within a vector have the same sizes? And by extension, that a property of all elements is the same? In the below examples, I use the hypothetical `std::all_equal` that I am looking for: ``` typedef std::vector<int> Line; std::vector<Line> lines; lines.push(Line(10)); lines.push(Line(11)); auto equalLengths = std::all_equal(lines.begin(), lines.end(), [](const Line& x){ return x.size(); }); ``` (And by extension: ``` std::vector<MyClass> vec; auto equal = std::all_equal(std::begin(vec), std::end(vec), [](const MyClass& x) { return x.property(); }); ``` )

Original source