#include <map>
#include <cstdio>
class NotCopyable
{
public:
NotCopyable(char key):m_x(key){}
NotCopyable(NotCopyable&& a)
{
printf("create %p from %p\n",this,&a);
m_x=a.m_x;
}
NotCopyable& operator=(NotCopyable&& a)
{
printf("move %p into %p\n",&a,this);
return *this;
}
bool operator<(const NotCopyable& nc) const
{return m_x<nc.m_x;}
char m_x;
};
int main()
{
std::map<NotCopyable,int> my_map;
my_map.insert(std::pair<NotCopyable,int>('A',1));
my_map.insert(std::pair<NotCopyable,int>('B',2));
my_map.insert(std::pair<NotCopyable,int>('C',3));
auto i=my_map.begin();
while(i!=my_map.end())
{
printf("'%c' => %d\n",i->first.m_x,i->second);
NotCopyable foo=std::move( *((NotCopyable*)(&i->first)) );
++i;
}
return 0;
}
I2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPGNzdGRpbz4KCmNsYXNzIE5vdENvcHlhYmxlCiAgICB7CglwdWJsaWM6CgkJTm90Q29weWFibGUoY2hhciBrZXkpOm1feChrZXkpe30KCQlOb3RDb3B5YWJsZShOb3RDb3B5YWJsZSYmIGEpCgkJCXsKCQkJcHJpbnRmKCJjcmVhdGUgJXAgZnJvbSAlcFxuIix0aGlzLCZhKTsKCQkJbV94PWEubV94OwoJCQl9CgkJCgkJTm90Q29weWFibGUmIG9wZXJhdG9yPShOb3RDb3B5YWJsZSYmIGEpCgkJCXsKCQkJcHJpbnRmKCJtb3ZlICVwIGludG8gJXBcbiIsJmEsdGhpcyk7CgkJCXJldHVybiAqdGhpczsKCQkJfQoJCWJvb2wgb3BlcmF0b3I8KGNvbnN0IE5vdENvcHlhYmxlJiBuYykgY29uc3QKCQkJe3JldHVybiBtX3g8bmMubV94O30KCQljaGFyIG1feDsKCX07CgppbnQgbWFpbigpCgl7CglzdGQ6Om1hcDxOb3RDb3B5YWJsZSxpbnQ+IG15X21hcDsKCW15X21hcC5pbnNlcnQoc3RkOjpwYWlyPE5vdENvcHlhYmxlLGludD4oJ0EnLDEpKTsKCW15X21hcC5pbn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