Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Widget
- {
- private:
- template<typename T>
- class Giver final
- {
- public:
- explicit Giver(T& host) : host_(host) {}
- Giver(Giver&& other)
- {
- other.ready = false;
- }
- Giver& operator=(Giver&& other)
- {
- other.ready = false;
- return *this;
- }
- void zig()
- {
- host_.zig();
- }
- void zag()
- {
- host_.zag();
- }
- ~Giver()
- {
- if (ready)
- {
- host_.end();
- ready = false;
- }
- }
- private:
- bool ready = true;
- T& host_;
- };
- void end()
- {
- std::cout << "end" << std::endl;
- }
- void zig()
- {
- std::cout << "zig" << std::endl;
- }
- void zag()
- {
- std::cout << "zag" << std::endl;
- }
- public:
- Giver<Widget> begin()
- {
- std::cout << "begin" << std::endl;
- return Giver<Widget>(*this);
- }
- };
- int _tmain(int argc, _TCHAR* argv[])
- {
- {
- Widget widget;
- auto giver = widget.begin();
- //Widget::Giver<Widget> giverr(widget);
- giver.zig();
- giver.zag();
- std::cout << "hell, yeah!" << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement