fork(1) download
  1. # 1 "main.cpp"
  2. # 1 "<built-in>"
  3. # 1 "<command-line>"
  4. # 1 "main.cpp"
  5. # 1 "B.h" 1
  6. # 1 "A.h" 1
  7. # 1 "pimpl.h" 1
  8.  
  9. #include <memory>
  10.  
  11. template<typename T>
  12. class pimpl
  13. {
  14. template <typename> friend class pimpl;
  15.  
  16. pimpl(const pimpl& other);
  17. pimpl(pimpl&& other);
  18. pimpl& operator=(const pimpl& other);
  19. pimpl& operator=(pimpl&& other);
  20. protected:
  21.  
  22. ~pimpl();
  23.  
  24. struct implementation;
  25. std::unique_ptr<implementation> impl_;
  26. public:
  27. pimpl();
  28.  
  29. template<typename P0>
  30. pimpl(P0&& p0);
  31.  
  32. pimpl(const T& other);
  33. pimpl(T&& other);
  34.  
  35. void swap(T& other);
  36. };
  37. # 2 "A.h" 2
  38.  
  39. struct A : public pimpl<A>
  40. {
  41. A();
  42. A(const A& other);
  43. A(A&& other);
  44. virtual ~A();
  45. void foo();
  46. };
  47. # 2 "B.h" 2
  48.  
  49. class B : public pimpl<B>, public A
  50. {
  51. public:
  52. B();
  53. B(const B& other);
  54. B(B&& other);
  55. virtual ~B();
  56. void bar();
  57. };
  58.  
  59. /////////////////////
  60. // pimpl_impl.h
  61.  
  62. template<typename T>
  63. pimpl<T>::pimpl() : impl_(new implementation()){}
  64.  
  65. template<typename T>
  66. template<typename P0>
  67. pimpl<T>::pimpl(P0&& p0) : impl_(new implementation(std::forward<P0>(p0))){}
  68.  
  69. template<typename T>
  70. pimpl<T>::~pimpl(){}
  71.  
  72. template<typename T>
  73. pimpl<T>::pimpl(const T& other) : impl_(new implementation(*((pimpl&)other).impl_)){}
  74.  
  75. template<typename T>
  76. pimpl<T>::pimpl(T&& other) : impl_(std::move(((pimpl&)other).impl_)){}
  77.  
  78. template<typename T>
  79. void pimpl<T>::swap(T& other)
  80. {
  81. impl_.swap(other.impl_);
  82. }
  83.  
  84. /////////////////////
  85. // A.cpp
  86.  
  87. template<>
  88. struct pimpl<A>::implementation
  89. {
  90. void foo()
  91. {
  92. }
  93. };
  94.  
  95. A::A() : pimpl(){}
  96. A::A(const A& other) : pimpl(other){}
  97. A::A(A&& other) : pimpl(std::move(other)){}
  98. A::~A(){}
  99. void A::foo(){impl_->foo();}
  100.  
  101. /////////////////////
  102. // B.cpp
  103.  
  104. template<>
  105. struct pimpl<B>::implementation
  106. {
  107. void bar()
  108. {
  109. }
  110. };
  111.  
  112. B::B() : pimpl<B>(){}
  113. B::B(const B& other) : pimpl<B>(other){}
  114. B::B(B&& other) : pimpl<B>(std::move(other)){}
  115. B::~B(){}
  116. void B::bar(){ pimpl<B>::impl_->bar();}
  117.  
  118.  
  119. # 2 "main.cpp" 2
  120.  
  121. int main()
  122. {
  123. A a;
  124. B b;
  125. }
  126.  
Success #stdin #stdout 0s 2956KB
stdin
Standard input is empty
stdout
Standard output is empty