daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. template <typename... Args, typename Func, std::size_t... Idx>
  2. void for_each(const std::tuple<Args...>& t, Func&& f, std::index_sequence<Idx...>) {
  3.     f(std::get<Idx>(t))...;
  4. }
  5.  
  6. template <typename... Args, typename Func>
  7. void for_each(const std::tuple<Args...>& t, Func&& f) {
  8.     for_each(t, f, std::index_sequence_for<Args...>{});
  9. }
  10.  
  11. template <typename T>
  12. void Write(std::wostream & out, const T & t)
  13. {
  14.     out << t;
  15. }
  16.  
  17. template<typename ...Args>
  18. void WriteV(std::wostream & out, Args&... args)
  19. {
  20.     for_each(std::tuple<Args&...>(args...), [&out](auto& a) { Write(out, a); });
  21. }
  22.  
  23. struct A
  24. {
  25.     int n;
  26.     std::wstring s;
  27.     double d;
  28. };
  29.  
  30.     void main()
  31.     {
  32.         std::wostringstream out;
  33.  
  34.         A a{ 1, std::wstring(L"2"), 3.0 };
  35.         Write(a.n, a.s, a.d);
  36.     }
  37.    
  38. error C2760: syntax error: unexpected token '...', expected ';'
  39. error C3520: 'Idx': parameter pack must be expanded in this context
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top