Advertisement
STANAANDREY

unknown params

Sep 4th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <utility>
  3. using namespace std;
  4.  
  5. class Console {
  6. protected:
  7.     template <typename T>
  8.     void log_argument(T t) {
  9.         std::cout << t << " ";
  10.     }
  11. public:
  12.     template <typename... Args>
  13.     void log(Args&&... args) {
  14.         int dummy[] = { 0, ((void) log_argument(std::forward<Args>(args)),0)... };
  15.         cout << endl;
  16.     }
  17.  
  18.     template <typename... Args>
  19.     void warn(Args&&... args) {
  20.         cout << "WARNING: ";
  21.         int dummy[] = { 0, ((void) log_argument(std::forward<Args>(args)),0)... };
  22.         cout << endl;
  23.     }
  24.  
  25.     template <typename... Args>
  26.     void error(Args&&... args) {
  27.         cout << "ERROR: ";
  28.         int dummy[] = { 0, ((void) log_argument(std::forward<Args>(args)),0)... };
  29.         cout << endl;
  30.     }
  31. };
  32.  
  33. int main()
  34. {
  35.     Console con;
  36.     con.log(5,7,8,9.88);
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement