Trimsky

VariadicTemplate.cpp

Jul 3rd, 2021
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <string>
  2. #include <string.h>
  3. #include <stdio.h>
  4.  
  5. std::string arg;
  6.  
  7. template<typename T>
  8. T add(T arg_){
  9.     return arg_;
  10. }
  11.  
  12. template<typename T, typename... Args>
  13. T add(T arg_, Args... args) {
  14.     char* str_cast = strdup(arg_);
  15.     strcat(str_cast, " ");
  16.     return strcat(str_cast, add(args...));
  17. }
  18.  
  19. template <typename... Args>
  20. void set_args(Args... args) noexcept {
  21.     arg += add(args...);
  22. }
  23.  
  24. int main() {
  25.     set_args("-O3", "-fsanitize=leak");
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment