Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eigen error: please_protect_your_min_with_parentheses

I'm trying to test Eigen's NonLinear Optimization capabilities by running the testcode that comes with the package.

I'm stuck (more like baffled) with these errors :

Error   5   error C2039: 'please_protect_your_min_with_parentheses' : is not a member of 'std::numeric_limits<double>'  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\eigen-eigen-5097c01bcdc4\unsupported\eigen\src\nonlinearoptimization\lmpar.h    184
Error   7   error C2039: 'please_protect_your_min_with_parentheses' : is not a member of 'std::numeric_limits<double>'  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\eigen-eigen-5097c01bcdc4\unsupported\eigen\src\nonlinearoptimization\lmpar.h    28
Error   6   error C2065: 'please_protect_your_min_with_parentheses' : undeclared identifier c:\program files (x86)\microsoft sdks\windows\v7.0a\include\eigen-eigen-5097c01bcdc4\unsupported\eigen\src\nonlinearoptimization\lmpar.h    184
Error   8   error C2065: 'please_protect_your_min_with_parentheses' : undeclared identifier c:\program files (x86)\microsoft sdks\windows\v7.0a\include\eigen-eigen-5097c01bcdc4\unsupported\eigen\src\nonlinearoptimization\lmpar.h    28

by the way the line that (I think)causes this goes like this:

#define min(A,B) please_protect_your_min_with_parentheses

and the errors refer to this line (in 2 different places mentioned above as lines 28 and 184):

const Scalar dwarf = std::numeric_limits<Scalar>::min();

Any advice shall and will be much appreciated

like image 798
Can Celik Avatar asked Dec 03 '12 21:12

Can Celik


1 Answers

It requests you to change the line to this one:

const Scalar dwarf = (std::numeric_limits<Scalar>::min)();

So that if min function-like macro is defined, it will not be substituted.

The problem is that Microsoft Windows headers define the min macro, so standard C++ code that includes Windows headers may fail to compile. The solution that portable C++ libraries implement is wrapping their calls to the standard min functions with parentheses, as above. The test code that you compile seems to check that this technique is used by the code.

The problem of the above approach is that you will not be able to perform an unqualified call to min(a,b) with argument dependent lookup, since adding parentheses causes the name to be looked up independent of the arguments.

Another solution that one can apply to her own code is to define the NOMINMAX flag before including any Windows header or undefining the min/max macros. This is not usually done by library code since they are not supposed to tweak the configuration of the user code.

like image 117
Yakov Galka Avatar answered Oct 12 '22 07:10

Yakov Galka