fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template <typename T>
  5. struct vec;
  6.  
  7. template <typename T, bool B>
  8. struct vec_impl;
  9.  
  10. template <typename T>
  11. struct vec_impl<T, true> {
  12. static void add(const vec<T>& self, const T& a) {
  13. T n(a);
  14. }
  15. };
  16.  
  17. template <typename T>
  18. class vec {
  19. friend struct vec_impl<T, true>;
  20.  
  21. public:
  22. virtual void add(const T& a) {
  23. vec_impl<T, std::is_copy_constructible<T>::value>::add(*this, a);
  24. }
  25.  
  26. virtual void add(T&& a) {
  27.  
  28. }
  29. };
  30.  
  31. struct mov {
  32. mov() = default;
  33. mov(const mov&) = delete;
  34. mov(mov&&) = default;
  35. };
  36.  
  37. int main() {
  38. mov m;
  39.  
  40. vec<mov> v;
  41.  
  42. v.add(std::move(m));
  43.  
  44. return 0;
  45. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘void vec<T>::add(const T&) [with T = mov]’:
prog.cpp:45:1:   required from here
prog.cpp:23:66: error: incomplete type ‘vec_impl<mov, false>’ used in nested name specifier
   vec_impl<T, std::is_copy_constructible<T>::value>::add(*this, a);
                                                                  ^
stdout
Standard output is empty