fork download
  1. #include <vector>
  2. #include <cstdlib>
  3. #include <cstdarg>
  4. #include <iterator>
  5. #include <iostream>
  6. namespace Interpolation
  7. {
  8. unsigned long DefaultRes = 1;
  9. template<class T, unsigned D>
  10. struct Node
  11. {
  12. Node(T const *Data, unsigned long Resolution = DefaultRes);
  13. T Data[D];
  14. unsigned long Resolution;
  15. };
  16. template<class T, unsigned D>
  17. Node<T, D> MakeNode(T First, ...);
  18. }
  19. template<class T, unsigned D>
  20. Interpolation::Node<T, D>::Node(T const *Data, unsigned long Resolution)
  21. : Resolution(Resolution)
  22. {
  23. for(unsigned i = 0; i < D; i++)
  24. this->Data[i] = Data[i];
  25. }
  26. template<class T, unsigned D>
  27. Interpolation::Node<T, D>
  28. Interpolation::MakeNode(T First, ...)
  29. {
  30. T Data[D] = {First};
  31. va_list Args;
  32. va_start(Args, First);
  33. for(unsigned i = 1; i < D; i++)
  34. Data[i] = va_arg(Args, T);
  35. va_end(Args);
  36. return Interpolation::Node<T, D>(Data);
  37. }
  38. int main()
  39. {
  40. using Interpolation::MakeNode;
  41. std::vector< ::Interpolation::Node<float, 2> > Data;
  42. Data.push_back(MakeNode<float, 2>(5, 5));
  43. std::cout << Data.front().Data[0] << ' ' << Data.front().Data[1];
  44. }
  45. static_assert(false,"show compiler output on ideone");
  46.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:45:1: error: static assertion failed: show compiler output on ideone
prog.cpp: In function ‘Interpolation::Node<T, D> Interpolation::MakeNode(T, ...) [with T = float; unsigned int D = 2u]’:
prog.cpp:34:9: warning: ‘float’ is promoted to ‘double’ when passed through ‘...’ [enabled by default]
prog.cpp:34:9: note: (so you should pass ‘double’ not ‘float’ to ‘va_arg’)
prog.cpp:34:9: note: if this code is reached, the program will abort
stdout
Standard output is empty