#Define Nominmax Using Std::Min/Max

#define NOMINMAX using std::min/max

If you're really desperate, put parentheses around the function names:

(std::min)(x, y);

This syntax won't apply a function-like macro. (Formally, to apply a function-like macro the name of the macro must be followed by optional white space then a '('.)

Possible problems with NOMINMAX on Visual C++

Using NOMINMAX is the only not-completely-evil way to include <windows.h>. You should also define UNICODE and STRICT. Although the latter is defined by default by modern implementations.

You can however run into problems with Microsoft’s headers, e.g. for GdiPlus. I’m not aware of problems with headers from any other companies or persons.

If the header defines a namespace, as GdiPlus does, then one fix is to create a wrapper for the relevant header, where you include <algorithm>, and inside the header’s namespace, using namespace std; (or alternatively using std::min; and using std::max):

#define NOMINMAX
#include <algorithm>
namespace Gdiplus
{
using std::min;
using std::max;
}

Note that that is very different from a using namespace std; at global scope in header, which one should never do.

I don’t know of any good workaround for the case where there's no namespace, but happily I haven’t run into that, so in practice that particular problem is probably moot.

Why is std::min failing when windows.h is included?

The windows.h header file (or more correctly, windef.h that it includes in turn) has macros for min and max which are interfering.

You should #define NOMINMAX before including it.

std::min/max type deduction different on linux and windows

If it is not a typo then in this statement

int minX = max(min(floor(v1[0]), min(floor(v2[0]), floor(v3[0]))), 0.0);

integer literal 9.9 has type double while other operands have type float. So the compiler can not decide whether to use template argument float or double

The error message says clear that for function

'const _Ty &std::max(const _Ty &,const _Ty &)' 

there could be 'double' or 'float'

That is the funcrion call looks as

std::max( float_value, double_value );

You could explicitly specify the template argument as for example

std::max<double>( float_value, double_value );

or

std::max<float>( float_value, double_value );

As for GCC then it places the standard C function floor that has return type double in the global namespace..

double floor(double x);

So the operands after applying this function are converted to the type double. But it seems that MS VC++ does not places this function in the global namespace or the global namespace in MS VC++ has overloaded functions with the same name.

So the problem is relative to what function(s) floor each compiler places in the global namespace.

I think that if you used qualified name std::floor then GCC would also issue an error.

So in your code MS VC++ uses function

float floor(float x);

and as the result issues the error while GCC uses function

double floor(double x);

and all operands of function std::max have type double and the code is compiled successfully.:)

How do I deal with the max macro in windows.h colliding with max in std?

Define the macro NOMINMAX:

This will suppress the min and max definitions in Windef.h.

Can't call std::max because minwindef.h defines max

You can undefine the macro:

#undef max

Edit: It seems the macros can be safely disabled by putting

#define NOMINMAX

before the header files that define them (most likely windef.h, which you probably include indirectly).

To avoid undefining the macro, you can simply wrap the function in parenthesis

(std::max)(...)

As noted by chris in the comments, function-like macros require the token after the macro name to be a left parenthesis in order to expand. Wrapping the name in parentheses is really just a hack to make the next token a right parenthesis without changing the meaning once you put macros aside.

Why does std::numeric_limits long long ::max() fail?

That max call may interfere with "evil" max preprocessor macro defined in the Windows SDK headers, that you have probably included (directly or indirectly).

An option is to prevent the preprocessor max macro to kick in, using an additional pair of parentheses:

... = (std::numeric_limits<long long>::max)();

As an additional option, you may consider #define #NOMINMAX before including Windows headers. This will prevent the definition of the aforementioned min and max preprocessor macros.

However, note that some Windows headers (like the GDI+ ones) do require the Win32's min and max preprocessor macros, so in such cases the use of an additional pair of parentheses may be a better option.

Embed one silverlight application in another silverlight application

What you probably want to do is to download a .xap file and then instantiate the root visual element from that .xap (e.g. "MainPage").

You will need to use WebClient to download the xap package. Then you can read that package as a stream and dynamically load the assemblies in it and instantiate a UserControl from the xap.

This blog post shows how to dynamically instantiate controls from a xap given a stream.



Related Topics



Leave a reply



Submit