fork download
  1. #include <iostream>
  2. #include <initializer_list>
  3. #include <array>
  4. #include <iterator>
  5. #include <algorithm>
  6.  
  7.  
  8. void InitializerWork ( std::initializer_list<int> arginit ) {
  9. for ( auto ip = arginit.begin(); ip != arginit.end(); ++ip ) {
  10. std::cout << *ip << std::endl;
  11. }
  12. std::cout << "So that's an initializer_list..." << std::endl;
  13. }
  14.  
  15. template<typename TDesired, typename T, std::size_t n>
  16. void GetArg ( const std::array<T, n> table, std::size_t& idx, const T& arg ) {
  17. table[idx++] = &arg;
  18. }
  19.  
  20. template <typename ...Args>
  21. void VariadicWork ( Args... args ) {
  22. std::array<const int*, sizeof...(args)> argtable;
  23. std::size_t index = 0;
  24. // ... What do?
  25. GetArg<int>( &argtable, index, args... );
  26. for ( auto ip = argtable.begin(); ip != argtable.end() ++ip ) {
  27. std::cout << *ip << std::endl;
  28. }
  29. std::cout << "That's... everything, I think." << std::endl;
  30. }
  31.  
  32.  
  33. int main (int argc, char* argv[]) {
  34.  
  35. InitializerWork( { 20, 40, 80 } );
  36. VariadicWork( 20, 40, 80 );
  37.  
  38. }
Compilation error #stdin compilation error #stdout 0s 2928KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void VariadicWork(Args ...)':
prog.cpp:26:62: error: expected ';' before 'ip'
prog.cpp: In function 'void VariadicWork(Args ...) [with Args = {int, int, int}]':
prog.cpp:36:30:   instantiated from here
prog.cpp:25:5: error: no matching function for call to 'GetArg(std::array<const int*, 3u>*, size_t&, int&, int&, int&)'
prog.cpp:36:30:   instantiated from here
prog.cpp:26:36: error: lvalue required as increment operand
stdout
Standard output is empty