#include <memory>
#include <vector>
//-----------------------------------------------------------------------------
class one
{
public:
one(){}
one(one&& other) : x(std::move(other.x)) {}
one& operator=(one&& other){ x = std::move(other.x); return *this; }
void swap(const one& other){ x.swap(other.x); }
void swap(one&& other){ x.swap(std::move(other.x)); }
private:
one(const one&);
one& operator=(const one&);
std::unique_ptr<int> x;
};
//-----------------------------------------------------------------------------
void swap(one& left, one& right)
{
left.swap(right);
}
//-----------------------------------------------------------------------------
void swap(one&& left, one& right)
{
right.swap(std::move(left));
}
//-----------------------------------------------------------------------------
void swap(one& left, one&& right)
{
left.swap(std::move(right));
}
//-----------------------------------------------------------------------------
class two
{
public:
two(){}
two(two&&){}
two& operator=(two&&){ return *this; }
operator one(){return one();}
private:
two(const two&);
two& operator=(const two&);
};
//-----------------------------------------------------------------------------
int main()
{
std::vector<two> twos(10);
std::vector<one> ones(std::make_move_iterator(twos.begin()), std::make_move_iterator(twos.end()));
}
I2luY2x1ZGUgPG1lbW9yeT4KI2luY2x1ZGUgPHZlY3Rvcj4KCi8vLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KY2xhc3Mgb25lCnsKcHVibGljOgogICAgb25lKCl7fQoJb25lKG9uZSYmIG90aGVyKSA6IHgoc3RkOjptb3ZlKG90aGVyLngpKSB7fQoJb25lJiBvcGVyYXRvcj0ob25lJiYgb3RoZXIpeyB4ID0gc3RkOjptb3ZlKG90aGVyLngpOyByZXR1cm4gKnRoaXM7IH0KCgl2b2lkIHN3YXAoY29uc3Qgb25lJiBvdGhlcil7IHguc3dhcChvdGhlci54KTsgfQoJdm9pZCBzd2FwKG9uZSYmIG90aGVyKXsgeC5zd2FwKHN0ZDo6bW92ZShvdGhlci54KSk7IH0KCnByaXZhdGU6CglvbmUoY29uc3Qgb25lJik7CglvbmUmIG9wZXJhdG9yPShjb25zdCBvbmUmKTsKCglzdGQ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LS0tLS0tLS0tLS0tLS0KaW50IG1haW4oKQp7CglzdGQ6OnZlY3Rvcjx0d28+IHR3b3MoMTApOwoJc3RkOjp2ZWN0b3I8b25lPiBvbmVzKHN0ZDo6bWFrZV9tb3ZlX2l0ZXJhdG9yKHR3b3MuYmVnaW4oKSksIHN0ZDo6bWFrZV9tb3ZlX2l0ZXJhdG9yKHR3b3MuZW5kKCkpKTsKfQ==
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