// std名前空間内に以下が定義されていると仮定
namespace std{
template<class T>
struct move_traits
{
typedef typename T::move_type move_type;
static move_type move(T &x){ return x.move(); }
};
template<class T>
typename move_traits<T>::move_type move(T &x)
{ return move_traits<T>::move(x); }
}
// ---------- 以下ライブラリコード ----------
template<class T>
class movable_vector
{
public:
/*...*/
struct move_type
{ movable_vector mv; };
movable_vector(move_type x)
: buf(0), sz(0)
{ std::swap(*this, x.mv); }
move_type move()
{
move_type tmp;
std::swap(*this, tmp.mv);
return tmp;
}
private:
move_ptr<T[]> buf;
std::size_t sz;
};
//---------- 以上ライブラリコード ----------
//---------- 以下クライアントコード ----------
movable_vector<int>::move_type f()
{
movable_vector<int> tmp(1000000);
/*...*/
return std::move(tmp);
}
int main()
{
movable_vector<int> v = f();
/*...*/
return 0;
}( ゜∀゜)アハハ八八ノヽノヽノヽノ \ / \/ \