How do I check if all the "sub-vectors"(what is the correct term?) are empty? if(???)error("Error : No values");
Excerpt of program :
1 2 3 4 5 6 7 8 9 10 11 12 13 14
vector< vector<int> >week_days(no_of_days); // seven days for a week
for (int i = 0; i < no_of_days; ++i){
vector<int>day;
week_days.push_back(day); // putting in 7 day vectors into the week_days vector
}
cout << "Enter day of week and value pairs\n";
string day = "sunday";
int value = 0;
for(day,value; cin >> day >> value;){
day_value_push(day,value); // taking in inputs
}cout << value;
if(???)error("Error : No values");
// http://coliru.stacked-crooked.com/a/9e2a20caccdb14f1
#include <iostream>
#include <string>
#include <vector>
template <typename ContainerType>
bool fully_populated(const ContainerType& container)
{
for (auto& contained : container)
if (contained.empty()) returnfalse;
returntrue;
}
int main()
{
using std::vector;
using std::cout;
using std::cin;
using std::string;
constunsigned no_of_days = 7;
vector< vector<int> >week_days(no_of_days); // seven days for a week
// redundant:
//for (int i = 0; i < no_of_days; ++i) {
// vector<int>day;
// week_days.push_back(day); // putting in 7 day vectors into the week_days vector
//}
for (unsigned i = 0; i < no_of_days - 1; ++i)
week_days[i].push_back(i);
if (!fully_populated(week_days))
std::cout << "There is at least one week day with no associated values.\n";
else
std::cout << "Fully populated.\n";
week_days[6].push_back(6);
if (!fully_populated(week_days))
std::cout << "There is at least one week day with no associated values.\n";
else
std::cout << "Fully populated.\n";
}