fork(3) download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template <std::size_t SIZE> class A
  5. {
  6. char b[SIZE];
  7.  
  8. public:
  9. using const_buffer_t = const char (&)[SIZE];
  10.  
  11. A() : b{} { std::cout << "size: " << SIZE << " ctor 1\n"; }
  12. A(const_buffer_t) : b{} { std::cout << "size: " << SIZE << " ctor 2\n"; }
  13. explicit A(const A&) : b{} { std::cout << "size: " << SIZE << " ctor 4\n"; }
  14.  
  15. template <typename T,
  16. typename=typename std::enable_if<
  17. std::is_same<typename std::remove_cv<T>::type, char>{}
  18. >::type>
  19. A(T* const&) : b{} { std::cout << "size: " << SIZE << " ctor 3\n"; }
  20.  
  21. template <std::size_t OTHER_SIZE>
  22. A(const char (&)[OTHER_SIZE]) : b{} { std::cout << "size: " << SIZE << " ctor 5\n"; }
  23.  
  24. template <std::size_t OTHER_SIZE>
  25. explicit A(const A<OTHER_SIZE> &) : b{} { std::cout << "size: " << SIZE << " ctor 6\n"; }
  26. };
  27.  
  28. int main()
  29. {
  30. A<5> a("five");
  31. A<5> b("0123456789");
  32. A<9> c(a);
  33. A<5> d;
  34. A<5> e(d);
  35. A<9> f(d);
  36. }
  37.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
size: 5 ctor 2
size: 5 ctor 5
size: 9 ctor 6
size: 5 ctor 1
size: 5 ctor 4
size: 9 ctor 6