fork(1) download
  1. #include <utility>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. template< class T >
  6. T&& my_forward( typename std::remove_reference<T>::type&& t )
  7. {
  8. return static_cast<T&&>(t);
  9. }
  10.  
  11. class Library
  12. {
  13. vector<int> b;
  14. public:
  15. // hi! only rvalue here :)
  16. Library( vector<int>&& a):b(std::move(a)){
  17.  
  18. }
  19. };
  20.  
  21. int main()
  22. {
  23. vector<int> v;
  24. v.push_back(1);
  25. Library a( my_forward<vector<int>>(v));
  26. return 0;
  27. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:25:41: error: no matching function for call to 'my_forward(std::vector<int>&)'
     Library a( my_forward<vector<int>>(v));
                                         ^
prog.cpp:25:41: note: candidate is:
prog.cpp:6:5: note: template<class T> T&& my_forward(typename std::remove_reference<_From>::type&&)
 T&& my_forward( typename std::remove_reference<T>::type&& t )
     ^
prog.cpp:6:5: note:   template argument deduction/substitution failed:
prog.cpp:25:41: note:   cannot convert 'v' (type 'std::vector<int>') to type 'std::remove_reference<std::vector<int> >::type&& {aka std::vector<int>&&}'
     Library a( my_forward<vector<int>>(v));
                                         ^
stdout
Standard output is empty