凡在的C ++ 0x是disable_if? [英] Where is disable_if in C++0x?

查看:104
本文介绍了凡在的C ++ 0x是disable_if?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升压既有 enable_if disable_if ,但的C ++ 0x似乎缺少了后者。为什么它留下了呢?是否有元编程中的C ++ 0x设施,让我建立 disable_if 而言 enable_if

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?

呵呵,我只注意到的std :: enable_if 基本的boost :: enable_if_c ,并且有没有这样的东西的boost :: enable_if C ++ 0x中。

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.

推荐答案

目前似乎愚蠢的风险,只是做!EX pression 而不是前pression 在布尔模板参数在 enable_if ,使它像一个 disable_if ?当然,如果这个想法的作品,你可以只扩大它来写与 disable_if A类样的行为?

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?

好吧,我相信你可以实现 disable_if 是这样的:

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> {
};

这篇关于凡在的C ++ 0x是disable_if?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆