Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CL {
- public:
- CL(){
- m_cars = std::vector<Car>();
- }
- CL(const std::vector<Car> &cars) {
- m_cars = cars;
- }
- CL(const Car &car) {
- m_cars = {car};
- }
- void find(int start, int end, const char *txt, std::list<Car> &result) {
- std::regex pattern(std::string(".*" + std::string(txt) + ".*"), std::regex_constants::icase);
- for (const auto &car: m_cars) {
- if (start < car.m_year && car.m_year < end) {
- if (std::regex_match(car.m_model, pattern) || std::regex_match(car.m_brand, pattern)) {
- result.emplace_back(car);
- }
- }
- }
- }
- friend std::ostream &operator<<(std::ostream &stream, const CL &cl);
- friend std::istream &operator>>(std::istream& is, CL& ocl);
- public:
- std::vector<Car> m_cars;
- };
- std::ostream &operator<<(std::ostream &os, const CL &cl) {
- os << "CL {";
- for (const auto &car: cl.m_cars) {
- os << "(brand: " << car.m_brand << ", model: " << car.m_model << ", year: " << car.m_year << "), ";
- }
- os << "}";
- return os;
- }
- std::istream &operator>>(std::istream& is, CL &cl) {
- std::string brand;
- std::string model;
- std::string year;
- is >> brand;
- is >> model;
- is >> year;
- cl.m_cars.emplace_back(brand, model, std::stoi(year));
- return is;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement