fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class T>
  5. struct identity
  6. {
  7. typedef T type;
  8. };
  9.  
  10. template <class T>
  11. T&& forward(typename identity<T>::type&& a)
  12. {
  13. return a;
  14. }
  15.  
  16.  
  17. int main() {
  18.  
  19. int a;
  20. forward( a );
  21.  
  22. return 0;
  23. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:20:13: error: no matching function for call to ‘forward(int&)’
  forward( a );
             ^
prog.cpp:20:13: note: candidates are:
prog.cpp:11:5: note: template<class T> T&& forward(typename identity<T>::type&&)
 T&& forward(typename identity<T>::type&& a)
     ^
prog.cpp:11:5: note:   template argument deduction/substitution failed:
prog.cpp:20:13: note:   couldn't deduce template parameter ‘T’
  forward( a );
             ^
In file included from /usr/include/c++/4.8/bits/stl_pair.h:59:0,
                 from /usr/include/c++/4.8/bits/stl_algobase.h:64,
                 from /usr/include/c++/4.8/bits/char_traits.h:39,
                 from /usr/include/c++/4.8/ios:40,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/move.h:87:5: note: template<class _Tp> constexpr _Tp&& std::forward(typename std::remove_reference<_From>::type&&)
     forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
     ^
/usr/include/c++/4.8/bits/move.h:87:5: note:   template argument deduction/substitution failed:
prog.cpp:20:13: note:   couldn't deduce template parameter ‘_Tp’
  forward( a );
             ^
In file included from /usr/include/c++/4.8/bits/stl_pair.h:59:0,
                 from /usr/include/c++/4.8/bits/stl_algobase.h:64,
                 from /usr/include/c++/4.8/bits/char_traits.h:39,
                 from /usr/include/c++/4.8/ios:40,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/move.h:76:5: note: template<class _Tp> constexpr _Tp&& std::forward(typename std::remove_reference<_From>::type&)
     forward(typename std::remove_reference<_Tp>::type& __t) noexcept
     ^
/usr/include/c++/4.8/bits/move.h:76:5: note:   template argument deduction/substitution failed:
prog.cpp:20:13: note:   couldn't deduce template parameter ‘_Tp’
  forward( a );
             ^
stdout
Standard output is empty