#include <iostream>
#include <string>
#include <functional>
#include <memory>

class X
{
    std::string m_s;

public:
    X () { }
    X (std::string s) { m_s = s; }
    ~X () { m_s = "destroyed"; std::cout << m_s << "\n"; }
    X (const X&) = delete;
    X& operator= (const X&) = delete;
    X (X&& other) { m_s = other.m_s; other.m_s.clear (); }
    X& operator= (X&& other) { m_s = other.m_s; other.m_s.clear (); return *this; };
    inline void Print() const { std::cout << m_s << "\n"; }
};

void foo (std::shared_ptr <X> x) { x->Print (); }

int main()
{
    std::function <void ()> f;

    {
        auto x = std::make_shared <X> ("Hello World!");
        f = [=] () { foo (x); };
    }

    f ();
}
