fork download
  1. #include <initializer_list>
  2. #include <iterator>
  3. #include <cstdio>
  4.  
  5. template <class T> T& minArgs(const std::initializer_list<T&> &Arguments)
  6. {
  7. const T* Smallest = Arguments.begin();
  8. for (const T* I = Arguments.begin(); I != Arguments.end(); ++I)
  9. {
  10. if (*I < *Smallest) Smallest = I;
  11. }
  12. return *Smallest;
  13. }
  14.  
  15. int main()
  16. {
  17. int min = minArgs({12, 44, 23});
  18. std::printf("%i\n", min);
  19. return 0;
  20. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:17:35: error: invalid initialization of reference of type 'const std::initializer_list<int&>&' from expression of type '<brace-enclosed initializer list>'
prog.cpp:5:23: error: in passing argument 1 of 'T& minArgs(const std::initializer_list<T&>&) [with T = int]'
In file included from prog.cpp:1:0:
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/initializer_list: At global scope:
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/initializer_list: In instantiation of 'std::initializer_list<int&>':
prog.cpp:7:41:   instantiated from 'T& minArgs(const std::initializer_list<T&>&) [with T = int]'
prog.cpp:17:35:   instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/initializer_list:52:26: error: forming pointer to reference type 'int&'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/initializer_list:53:26: error: forming pointer to reference type 'int&'
prog.cpp: In function 'T& minArgs(const std::initializer_list<T&>&) [with T = int]':
prog.cpp:17:35:   instantiated from here
prog.cpp:7:41: error: 'const class std::initializer_list<int&>' has no member named 'begin'
prog.cpp:8:39: error: 'const class std::initializer_list<int&>' has no member named 'begin'
prog.cpp:8:39: error: 'const class std::initializer_list<int&>' has no member named 'end'
prog.cpp:12:13: error: invalid initialization of reference of type 'int&' from expression of type 'const int'
stdout

Standard output is empty