删除类的所有RVALUE功能超载

发布于 2025-02-03 22:15:51 字数 549 浏览 2 评论 0原文

假设我有一个类对象,当从函数调用返回该类的对象时,呼叫者必须捕获必须捕获

// no_can_rvalue *must* be captured
[[nodiscard]] no_can_rvalue a_func();

我可以通过删除所有RVALUE函数过载来强制执行此功能,从而无法使用类功能,除非呼叫者捕获了它的对象(c ++ 17中的nodiscard加倍)。

是否可以删除给定类的全部 rvalue函数过载。

结果等同于:

struct no_can_rvalue {
    void f() && = delete;
    void f() &;
    void g() && = delete;
    void g() &;
    // etc
};

Say I have a class object that must be captured by the caller when returning this class's object from a function call.

// no_can_rvalue *must* be captured
[[nodiscard]] no_can_rvalue a_func();

I can enforce this by deleting all rvalue function overloads, thus making it impossible to use the class functionality unless a caller has captured an object of it (doubled with nodiscard in c++17).

Is it possible to delete all rvalue function overloads of a given class in one fell swoop?

The result being equivalent to :

struct no_can_rvalue {
    void f() && = delete;
    void f() &;
    void g() && = delete;
    void g() &;
    // etc
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你是年少的欢喜 2025-02-10 22:15:51

不,不可能这样做。

No, it is not possible to do so.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文