Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is disable_if in C++0x?

Tags:

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.

like image 554
fredoverflow Avatar asked Jun 24 '10 14:06

fredoverflow


People also ask

What are the options to control the dialect of C?

Options Controlling C Dialect The following options control the dialect of C (or languages derived from C, such as C++, Objective-C and Objective-C++) that the compiler accepts: -ansi In C mode, this is equivalent to -std=c90. In C++ mode, it is equivalent to -std=c++98.

How to cancel the bias toward speed of the /ox compiler option?

You can cancel the bias toward speed of the /Ox compiler option if you specify /Oxs, which combines the /Ox compiler option with /Os (Favor Small Code). The combined options favor smaller code size. The /Oxs option is exactly the same as specifying /Ox /Os when the options appear in that order.

How to enable and disable macros in Excel?

In the left menu, select Macro Settings, choose Disable all macros without notification, and click OK. That's how you can enable and disable macros in Excel.

Why does enable_if not work on a function template?

This does not work because the declarations are treated as redeclarations of the same function template (default template arguments are not accounted for in function template equivalence ). Care should be taken when using enable_if in the type of a template non-type parameter of a namespace-scope function template.


1 Answers

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> { }; 
like image 141
Jacob Avatar answered Oct 08 '22 01:10

Jacob