Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MyTinySTL: 考虑用作用域防护机制避免 try-catch-throw #106

Open
frederick-vs-ja opened this issue Jun 24, 2022 · 2 comments
Open

Comments

@frederick-vs-ja
Copy link
Contributor

如题,机制类似:

struct Guard {
    ContainerType* p_container_;
    ~Guard() {
        if (p_container_)
            p_container_->rollback_operation();
    }
};

在需要异常回滚的代码之前创建一个 Guard 对象:

Guard guard_{this};

在操作成功后将防护废弃掉:

guard_.p_container_ = nullptr;
@TY-cc
Copy link

TY-cc commented Jul 14, 2022

大佬,我都看不懂。。

@Adeshen
Copy link

Adeshen commented Jul 14, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants