Maybe < Customer const > getCustomer(Customers const &customers, std::string const &id) { auto customer = customers.find(id); if (customer == customers.end()) return nothing(); else return just(customer->second); };
void Persist::saveCustomers(Customers& customers) { Customers::iterator iterator; const char* fileName = Customer::FILE_NAME.c_str(); std::ofstream file(fileName, std::ios::out); if (!file) { std::cerr << "Error while opening " << fileName << std::endl; exit(EXIT_FAILURE); } for (iterator = customers.begin(); iterator != customers.end(); ++iterator) { Customer customer = (*iterator).second; file.write(reinterpret_cast<const char*>(&customer), sizeof(Customer)); } file.close(); }