Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "database.h"
- using namespace std;
- void Database::Add(const Date& date, const std::string& event) {
- base_vector.push_back(make_pair(date, event));
- stable_sort(base_vector.begin(), base_vector.end(),
- [](const pair<Date, string>& lhs,
- const pair<Date, string>& rhs) {
- return lhs.first < rhs.first;
- });
- }
- void Database::Print(ostream& is) {
- Date chek = base_vector.begin()->first;
- for (auto it = base_vector.begin(); it < base_vector.end(); it++) {
- if (it == base_vector.begin()) {
- is << it->first << ' ' << it->second << ' ';
- }
- if (it->first == chek) {
- is << it->second << ' ';
- }
- else if (it->first != chek) {
- is << endl << it->first << ' ' << it->second << ' ';
- }
- }
- }
- std::string Database::Last(const Date& a) {
- auto r = lower_bound(base_vector.begin(), base_vector.end(), [a](const pair<Date, std::string>& i) {
- return i.first < a;
- });
- return r->second;
- }
- ostream& operator << (std::ostream& stream, const std::pair<Date, string>& a) {
- stream << a.first << ' ' << a.second;
- return stream;
- }
- bool operator <(const std::pair<Date, string>& lhs, const std::pair<Date, string>& rhs) {
- return lhs.first < rhs.first;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement