fork download
  1. #include <memory>
  2. #include <vector>
  3.  
  4. //-----------------------------------------------------------------------------
  5. class one
  6. {
  7. public:
  8. one(){}
  9. one(one&& other) : x(std::move(other.x)) {}
  10. one& operator=(one&& other){ x = std::move(other.x); return *this; }
  11.  
  12. void swap(const one& other){ x.swap(other.x); }
  13. void swap(one&& other){ x.swap(std::move(other.x)); }
  14.  
  15. private:
  16. one(const one&);
  17. one& operator=(const one&);
  18.  
  19. std::unique_ptr<int> x;
  20. };
  21.  
  22. //-----------------------------------------------------------------------------
  23. void swap(one& left, one& right)
  24. {
  25. left.swap(right);
  26. }
  27.  
  28. //-----------------------------------------------------------------------------
  29. void swap(one&& left, one& right)
  30. {
  31. right.swap(std::move(left));
  32. }
  33.  
  34. //-----------------------------------------------------------------------------
  35. void swap(one& left, one&& right)
  36. {
  37. left.swap(std::move(right));
  38. }
  39.  
  40. //-----------------------------------------------------------------------------
  41. class two
  42. {
  43. public:
  44. two(){}
  45. two(two&&){}
  46. two& operator=(two&&){ return *this; }
  47.  
  48. operator one(){return one();}
  49.  
  50. private:
  51. two(const two&);
  52. two& operator=(const two&);
  53. };
  54.  
  55. //-----------------------------------------------------------------------------
  56. int main()
  57. {
  58. std::vector<two> twos(10);
  59. std::vector<one> ones(std::make_move_iterator(twos.begin()), std::make_move_iterator(twos.end()));
  60. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function 'void one::swap(const one&)':
prog.cpp:12:45: error: no matching function for call to 'std::unique_ptr<int>::swap(const std::unique_ptr<int>&)'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/unique_ptr.h:200:7: note: candidate is: void std::unique_ptr<_Tp, _Tp_Deleter>::swap(std::unique_ptr<_Tp, _Tp_Deleter>&) [with _Tp = int, _Tp_Deleter = std::default_delete<int>, std::unique_ptr<_Tp, _Tp_Deleter> = std::unique_ptr<int>]
prog.cpp: In member function 'void one::swap(one&&)':
prog.cpp:13:51: error: no matching function for call to 'std::unique_ptr<int>::swap(std::remove_reference<std::unique_ptr<int>&>::type)'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/unique_ptr.h:200:7: note: candidate is: void std::unique_ptr<_Tp, _Tp_Deleter>::swap(std::unique_ptr<_Tp, _Tp_Deleter>&) [with _Tp = int, _Tp_Deleter = std::default_delete<int>, std::unique_ptr<_Tp, _Tp_Deleter> = std::unique_ptr<int>]
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/memory:65:0,
                 from prog.cpp:1:
prog.cpp: In function 'void std::_Construct(_T1*, _T2&&) [with _T1 = two, _T2 = const two&]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_uninitialized.h:248:3:   instantiated from 'static void std::__uninitialized_fill_n<<anonymous> >::uninitialized_fill_n(_ForwardIterator, _Size, const _Tp&) [with _ForwardIterator = two*, _Size = unsigned int, _Tp = two, bool <anonymous> = false]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_uninitialized.h:284:7:   instantiated from 'void std::uninitialized_fill_n(_ForwardIterator, _Size, const _Tp&) [with _ForwardIterator = two*, _Size = unsigned int, _Tp = two]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_uninitialized.h:379:7:   instantiated from 'void std::__uninitialized_fill_n_a(_ForwardIterator, _Size, const _Tp&, std::allocator<_Tp2>&) [with _ForwardIterator = two*, _Size = unsigned int, _Tp = two, _Tp2 = two]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_vector.h:1039:2:   instantiated from 'void std::vector<_Tp, _Alloc>::_M_fill_initialize(std::vector::size_type, const value_type&) [with _Tp = two, _Alloc = std::allocator<two>, std::vector::size_type = unsigned int, value_type = two]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_vector.h:230:9:   instantiated from 'std::vector<_Tp, _Alloc>::vector(std::vector::size_type, const value_type&, const allocator_type&) [with _Tp = two, _Alloc = std::allocator<two>, std::vector::size_type = unsigned int, value_type = two, allocator_type = std::allocator<two>]'
prog.cpp:58:26:   instantiated from here
prog.cpp:51:2: error: 'two::two(const two&)' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_construct.h:80:7: error: within this context
stdout
Standard output is empty