C++0x 中的disable_if 在哪里?

发布于 2024-09-07 01:32:36 字数 303 浏览 0 评论 0原文

Boost 同时具有 enable_ifdisable_if,但 C++0x 似乎缺少后者。为什么它被排除在外? C++0x 中是否有元编程工具允许我根据 enable_if 构建 disable_if


哦,我刚刚注意到 std::enable_if 基本上是 boost::enable_if_c,并且没有 boost::enable_if 这样的东西在 C++0x 中。

Boost has both enable_if and disable_if, but C++0x seems to be missing the latter. Why was it left out? Are there meta-programming facilities in C++0x that allow me to build disable_if in terms of enable_if?


Oh, I just noticed that std::enable_if is basically boost::enable_if_c, and that there is no such thing as boost::enable_if in C++0x.

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

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

发布评论

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

评论(1

So尛奶瓶 2024-09-14 01:32:36

冒着看似愚蠢的风险,只需在 enable_if 中的 bool 模板参数中执行 !expression 而不是 expression 即可使其表现得像 >disable_if?当然,如果这个想法可行,您可以扩展它来编写一个具有类似 disable_if 行为的类吗?

好的,我相信你可以像这样实现 disable_if

template <bool B, typename T = void>
struct disable_if {
    typedef T type;
};

template <typename T>
struct disable_if<true,T> {
};

At the risk of seeming stupid, just do !expression instead of expression in the bool template parameter in enable_if to make it behave like a disable_if? Of course if that idea works, you could just expand on it to write a class with disable_if-like behavior?

Ok, I believe you could implement disable_if like this:

template <bool B, typename T = void>
struct disable_if {
    typedef T type;
};

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