fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class foo {
  5. int data;
  6. public:
  7. template <typename T, typename = enable_if_t<is_constructible<T, int>::value>>
  8. foo(const T& i) : data{ i } { cout << "Value copy ctor" << endl; }
  9.  
  10. template <typename T, typename = enable_if_t<is_constructible<T, int>::value>>
  11. foo(T&& i) : data{ i } { cout << "Value move ctor" << endl; }
  12.  
  13. foo(const foo& other) : data{ other.data } { cout << "Copy ctor" << endl; }
  14.  
  15. foo(foo&& other) : data{ other.data } { cout << "Move ctor" << endl; }
  16.  
  17. operator int() { cout << "Operator int()" << endl; return data; }
  18. };
  19.  
  20. int main() {
  21. foo obj1(42);
  22. foo obj2(obj1);
  23. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Value move ctor
Copy ctor