Last active
September 11, 2016 09:54
-
-
Save matsuokah/9e7aba6ef4d919682e18940d5fa8746f to your computer and use it in GitHub Desktop.
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> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
struct food { | |
public: | |
food(){}; | |
food(const std::string &id, const std::string name, | |
const std::uint32_t quantity) | |
: id{id}, name{name}, quantity{quantity}, is_empty{false} {}; | |
food(const std::string &id, const std::string name, | |
const std::uint32_t quantity, bool is_empty) | |
: id{id}, name{name}, quantity{quantity}, is_empty{is_empty} {}; | |
food(const food &f) | |
: id{f.id}, name{f.name}, quantity{f.quantity}, is_empty{f.is_empty} {}; | |
std::string id; | |
std::string name; | |
std::uint32_t quantity; | |
bool is_empty; | |
static food make_empty() { return {"", "", 0, true}; } | |
}; | |
std::ostream &operator<<(std::ostream &os, const food &f) { | |
os << "[" | |
<< "id: " << f.id << ", " | |
<< "name: " << f.name << ", " | |
<< "quantity: " << f.quantity << ", " | |
<< "is_empty: " << std::boolalpha << f.is_empty << "]"; | |
return os; | |
} | |
int main() { | |
auto columns = 4; | |
std::vector<food> foods = { | |
{"a", "ramen", 1}, {"b", "tsukemen", 2}, {"c", "rice", 3}, | |
{"d", "soy", 4}, {"e", "chiken", 5}, {"f", "beef", 6}, | |
{"g", "poke", 7}, | |
}; | |
auto empty_cell = columns - foods.size() % columns; | |
std::fill_n(std::back_inserter(foods), empty_cell, food::make_empty()); | |
std::cout << "foods: " << foods.size() << std::endl | |
<< "empty_cell: " << empty_cell << std::endl; | |
for (auto &f : foods) { | |
std::cout << f << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment