fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template<typename T>
  5. typename std::enable_if<
  6. std::is_const<typename std::remove_reference<T>::type>::value
  7. >::type
  8. forwarder(T&& x)
  9. {
  10. auto value_cat = std::is_rvalue_reference<decltype(x)>::value ? "r" : "l";
  11. std::cout << value_cat << "value reference to const\n";
  12. }
  13.  
  14. int main()
  15. {
  16. const int x = 42;
  17. forwarder(std::move(x));
  18. forwarder(x);
  19. int y = 42;
  20. forwarder(std::move(y));
  21. forwarder(y);
  22. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:20:27: error: no matching function for call to ‘forwarder(std::remove_reference<int&>::type)’
     forwarder(std::move(y));
                           ^
prog.cpp:20:27: note: candidate is:
prog.cpp:8:1: note: template<class T> typename std::enable_if<std::is_const<typename std::remove_reference< <template-parameter-1-1> >::type>::value>::type forwarder(T&&)
 forwarder(T&& x)
 ^
prog.cpp:8:1: note:   template argument deduction/substitution failed:
prog.cpp: In substitution of ‘template<class T> typename std::enable_if<std::is_const<typename std::remove_reference< <template-parameter-1-1> >::type>::value>::type forwarder(T&&) [with T = int]’:
prog.cpp:20:27:   required from here
prog.cpp:8:1: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
prog.cpp:21:16: error: no matching function for call to ‘forwarder(int&)’
     forwarder(y);
                ^
prog.cpp:21:16: note: candidate is:
prog.cpp:8:1: note: template<class T> typename std::enable_if<std::is_const<typename std::remove_reference< <template-parameter-1-1> >::type>::value>::type forwarder(T&&)
 forwarder(T&& x)
 ^
prog.cpp:8:1: note:   template argument deduction/substitution failed:
prog.cpp: In substitution of ‘template<class T> typename std::enable_if<std::is_const<typename std::remove_reference< <template-parameter-1-1> >::type>::value>::type forwarder(T&&) [with T = int&]’:
prog.cpp:21:16:   required from here
prog.cpp:8:1: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
stdout
Standard output is empty