fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. namespace so
  5. {
  6. struct _base_ {};
  7.  
  8. struct _foo1_{};
  9. struct _foo2_{};
  10. struct _foo3_{};
  11.  
  12. class _derived_: public _base_
  13. {
  14. public:
  15. _derived_() = default;
  16.  
  17. _derived_(_derived_ const & _obj)
  18. : _base_(_obj)
  19. {
  20. std::cout << "Constructed from _derived_" << std::endl;
  21. }
  22.  
  23. _derived_(_base_ const & _obj)
  24. : _base_(_obj)
  25. {
  26. std::cout << "Constructed from _base_" << std::endl;
  27. }
  28.  
  29. template <typename _t_, typename = typename std::enable_if<
  30. std::is_same<_t_, _foo1_>::value || std::is_same<_t_, _foo2_>::value ||
  31. std::is_same<_t_, _foo3_>::value>::type>
  32. _derived_(_t_ const &)
  33. : _base_()
  34. {
  35. std::cout << "Constructed from _fooN_ using generic algorithm" << std::endl;
  36. }
  37.  
  38. ~_derived_() noexcept (true) = default;
  39. };
  40. } //namespace so
  41.  
  42.  
  43. int main()
  44. {
  45. so::_base_ b_{};
  46. so::_derived_ d_{};
  47. so::_foo1_ f1_{};
  48. so::_foo2_ f2_{};
  49. so::_foo3_ f3_{};
  50.  
  51. so::_derived_ db_{b_};
  52. so::_derived_ dd_{d_};
  53. so::_derived_ df1_{f1_};
  54. so::_derived_ df2_{f2_};
  55. so::_derived_ df3_{f3_};
  56.  
  57. return (0);
  58. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Constructed from _base_
Constructed from _derived_
Constructed from _fooN_ using generic algorithm
Constructed from _fooN_ using generic algorithm
Constructed from _fooN_ using generic algorithm