fork(2) download
  1. #include <iterator>
  2. #include <vector>
  3. #include <stdexcept>
  4.  
  5. template <typename It>
  6. typename std::iterator_traits<It>::reference
  7. access(It it, It end) {
  8. return it == end? throw std::runtime_error("no element"): *it;
  9. }
  10.  
  11. int main()
  12. {
  13. std::vector<int> v;
  14. access(v.begin(), v.end());
  15. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘typename std::iterator_traits<_Iterator>::reference access(It, It) [with It = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::iterator_traits<_Iterator>::reference = int&]’:
prog.cpp:14:30:   required from here
prog.cpp:8:64: error: invalid initialization of non-const reference of type ‘std::__iterator_traits<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, true>::reference {aka int&}’ from an rvalue of type ‘int’
     return it == end? throw std::runtime_error("no element"): *it;
                                                                ^
prog.cpp: In function ‘typename std::iterator_traits<_Iterator>::reference access(It, It) [with It = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::iterator_traits<_Iterator>::reference = int&]’:
prog.cpp:9:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty