Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #ifndef MAP_FILT_H
  2. #define MAP_FILT_H
  3.  
  4. #include <vector>
  5. #include <map>
  6.  
  7. template<typename T, typename T2, class Func>
  8. class map_filter_view
  9. {
  10.   private:
  11.   std::map<T, T2>& myMap;
  12.   Func func;
  13.   public:
  14.   map_filter_view(std::map<T, T2>& myMap)
  15.   {
  16.     this->myMap = myMap;
  17.   }
  18.  
  19.   int count (T key) const
  20.   {
  21.     int sum = 0;
  22.     for (std::pair<T, T2>& item : myMap)
  23.     {
  24.       if (!func(item) && item.first == key)
  25.       {
  26.         ++sum;
  27.       }
  28.     }
  29.     return sum;
  30.   }
  31.  
  32.   int size () const
  33.   {
  34.     int sum = 0;
  35.     for (std::pair<T, T2>& item : myMap)
  36.     {
  37.       if (!func(item))
  38.       {
  39.         ++sum;
  40.       }
  41.     }
  42.     return sum;
  43.   }
  44. };
  45. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement