fork download
  1. #include <memory>
  2. #include <utility>
  3. #include <iostream>
  4.  
  5.  
  6. template <class T>
  7. class Hoge {
  8. std::unique_ptr<T> p;
  9. Hoge(Hoge const & o);
  10. Hoge & operator = (Hoge const & o);
  11. public:
  12. explicit Hoge(T && o): p(new T(std::move(o))) { }
  13. explicit Hoge(T const & o): p(new T(o)) { }
  14. Hoge(Hoge && o): p(std::move(o.p)) { }
  15. Hoge & operator = (Hoge && o) { p.swap(o.p); }
  16. template <class U> void operator () (U * q) const { (*p)(q); }
  17. };
  18.  
  19. template <class T>
  20. Hoge<T> MakeHoge(T && o) { return Hoge<T>(std::forward<T>(o)); }
  21.  
  22.  
  23. int main(void) {
  24. auto d = MakeHoge([] (int * p) { std::cout << "DELETE!" << std::endl; delete p; });
  25. std::shared_ptr<int> pair(new int(0), std::move(d));
  26. return 0;
  27. }
  28.  
  29.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/memory:101:0,
                 from prog.cpp:1:
prog.cpp: In constructor 'std::shared_ptr<_Tp>::shared_ptr(_Tp1*, _Deleter) [with _Tp1 = int, _Deleter = Hoge<main()::<lambda(int*)> >, _Tp = int]':
prog.cpp:25:55:   instantiated from here
prog.cpp:9:5: error: 'Hoge<T>::Hoge(const Hoge<T>&) [with T = main()::<lambda(int*)>, Hoge<T> = Hoge<main()::<lambda(int*)> >]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr.h:123:66: error: within this context
prog.cpp:25:55:   instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr.h:123:66: error:   initializing argument 2 of 'std::__shared_ptr<_Tp, _Lp>::__shared_ptr(_Tp1*, _Deleter) [with _Tp1 = int, _Deleter = Hoge<main()::<lambda(int*)> >, _Tp = int, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr.h:52:0,
                 from /usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/memory:101,
                 from prog.cpp:1:
prog.cpp: In constructor 'std::__shared_ptr<_Tp, _Lp>::__shared_ptr(_Tp1*, _Deleter) [with _Tp1 = int, _Deleter = Hoge<main()::<lambda(int*)> >, _Tp = int, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr.h:123:66:   instantiated from 'std::shared_ptr<_Tp>::shared_ptr(_Tp1*, _Deleter) [with _Tp1 = int, _Deleter = Hoge<main()::<lambda(int*)> >, _Tp = int]'
prog.cpp:25:55:   instantiated from here
prog.cpp:9:5: error: 'Hoge<T>::Hoge(const Hoge<T>&) [with T = main()::<lambda(int*)>, Hoge<T> = Hoge<main()::<lambda(int*)> >]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr_base.h:554:37: error: within this context
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr_base.h:554:37: error:   initializing argument 2 of 'std::__shared_count<_Lp>::__shared_count(_Ptr, _Deleter) [with _Ptr = int*, _Deleter = Hoge<main()::<lambda(int*)> >, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'
prog.cpp: In constructor 'std::__shared_count<_Lp>::__shared_count(_Ptr, _Deleter) [with _Ptr = int*, _Deleter = Hoge<main()::<lambda(int*)> >, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr_base.h:554:37:   instantiated from 'std::__shared_ptr<_Tp, _Lp>::__shared_ptr(_Tp1*, _Deleter) [with _Tp1 = int, _Deleter = Hoge<main()::<lambda(int*)> >, _Tp = int, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr.h:123:66:   instantiated from 'std::shared_ptr<_Tp>::shared_ptr(_Tp1*, _Deleter) [with _Tp1 = int, _Deleter = Hoge<main()::<lambda(int*)> >, _Tp = int]'
prog.cpp:25:55:   instantiated from here
prog.cpp:9:5: error: 'Hoge<T>::Hoge(const Hoge<T>&) [with T = main()::<lambda(int*)>, Hoge<T> = Hoge<main()::<lambda(int*)> >]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr_base.h:264:8: error: within this context
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr_base.h:264:8: error:   initializing argument 2 of 'std::_Sp_counted_deleter<_Ptr, _Deleter, _Alloc, _Lp>::_Sp_counted_deleter(_Ptr, _Deleter) [with _Ptr = int*, _Deleter = Hoge<main()::<lambda(int*)> >, _Alloc = std::allocator<int>, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'
prog.cpp: In constructor 'std::_Sp_counted_deleter<_Ptr, _Deleter, _Alloc, _Lp>::_Sp_counted_deleter(_Ptr, _Deleter) [with _Ptr = int*, _Deleter = Hoge<main()::<lambda(int*)> >, _Alloc = std::allocator<int>, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr_base.h:264:8:   instantiated from 'std::__shared_count<_Lp>::__shared_count(_Ptr, _Deleter) [with _Ptr = int*, _Deleter = Hoge<main()::<lambda(int*)> >, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr_base.h:554:37:   instantiated from 'std::__shared_ptr<_Tp, _Lp>::__shared_ptr(_Tp1*, _Deleter) [with _Tp1 = int, _Deleter = Hoge<main()::<lambda(int*)> >, _Tp = int, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr.h:123:66:   instantiated from 'std::shared_ptr<_Tp>::shared_ptr(_Tp1*, _Deleter) [with _Tp1 = int, _Deleter = Hoge<main()::<lambda(int*)> >, _Tp = int]'
prog.cpp:25:55:   instantiated from here
prog.cpp:9:5: error: 'Hoge<T>::Hoge(const Hoge<T>&) [with T = main()::<lambda(int*)>, Hoge<T> = Hoge<main()::<lambda(int*)> >]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr_base.h:134:46: error: within this context
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr_base.h:134:46: error:   initializing argument 1 of 'std::_Sp_counted_deleter<_Ptr, _Deleter, _Alloc, _Lp>::_My_Deleter::_My_Deleter(_Deleter, const _Alloc&) [with _Ptr = int*, _Deleter = Hoge<main()::<lambda(int*)> >, _Alloc = std::allocator<int>, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'
prog.cpp: In constructor 'std::_Sp_counted_deleter<_Ptr, _Deleter, _Alloc, _Lp>::_My_Deleter::_My_Deleter(_Deleter, const _Alloc&) [with _Ptr = int*, _Deleter = Hoge<main()::<lambda(int*)> >, _Alloc = std::allocator<int>, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr_base.h:134:46:   instantiated from 'std::_Sp_counted_deleter<_Ptr, _Deleter, _Alloc, _Lp>::_Sp_counted_deleter(_Ptr, _Deleter) [with _Ptr = int*, _Deleter = Hoge<main()::<lambda(int*)> >, _Alloc = std::allocator<int>, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr_base.h:264:8:   instantiated from 'std::__shared_count<_Lp>::__shared_count(_Ptr, _Deleter) [with _Ptr = int*, _Deleter = Hoge<main()::<lambda(int*)> >, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr_base.h:554:37:   instantiated from 'std::__shared_ptr<_Tp, _Lp>::__shared_ptr(_Tp1*, _Deleter) [with _Tp1 = int, _Deleter = Hoge<main()::<lambda(int*)> >, _Tp = int, __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr.h:123:66:   instantiated from 'std::shared_ptr<_Tp>::shared_ptr(_Tp1*, _Deleter) [with _Tp1 = int, _Deleter = Hoge<main()::<lambda(int*)> >, _Tp = int]'
prog.cpp:25:55:   instantiated from here
prog.cpp:9:5: error: 'Hoge<T>::Hoge(const Hoge<T>&) [with T = main()::<lambda(int*)>, Hoge<T> = Hoge<main()::<lambda(int*)> >]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/shared_ptr_base.h:125:37: error: within this context
stdout
Standard output is empty