W_A_S_A_B_I

khdytt87r79

Apr 13th, 2023
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. // Посмотрите на структуру StopsForBusResponse
  2. // ...
  3. struct StopsForBusResponse {
  4.     // Константные указатели на контейнеры
  5.     // Это нормальная практика или так делать не стоит?
  6.     const string& bus;
  7.     const vector<string>& b2s;
  8.     const map<string, vector<string>>& s2b;
  9. };
  10.  
  11. ostream& operator<<(ostream& os, const StopsForBusResponse& r) {
  12.     // Выводим информацию в поток
  13.     return os;
  14. }
  15. class BusManager {
  16.     map<string, vector<string>> buses_to_stops_;
  17.     map<string, vector<string>> stops_to_buses_;
  18.  
  19. public:
  20.     // ...
  21.     StopsForBusResponse GetStopsForBus(const string& bus) const {
  22.         // На это не смотрим:
  23.         vector<string> a; // Заглушка
  24.         map<string, vector<string>> b; // Заглушка
  25.  
  26.         if (buses_to_stops_.count(bus) == 0) {
  27.             return { bus, a, b };
  28.         }
  29.  
  30.         // Вот этот стейтмент:
  31.         return { bus, buses_to_stops_.at(bus), stops_to_buses_ };
  32.     }
  33.     // ...
  34. };
Advertisement
Add Comment
Please, Sign In to add comment