RE: Some trouble with qldefines.hpp
Posted by Luigi Ballabio-4 on Nov 02, 2001; 4:50am
URL: http://quantlib.414.s1.nabble.com/Some-trouble-with-qldefines-hpp-tp1787p1791.html
At 12:49 PM 11/2/01 +0100, Jens Thiel wrote:
> > -----Original Message-----
> > From: Nicolas Di Césaré
>
> > I add NOMINMAX in the preprocessor definitions and it works fine
> > if I redefine min/max functions.
> >
> > I think that the 1st solution is better because we just have to change
> > qldefines.hpp file. With the second one, we have to define
> > NOMINMAX in each new project.
We might define it in qldefines.hpp---or rather in config.msvc.hpp which
config.hpp includes if the compiler is Visual C++. I'm not sure how solid
that would be, though: it would work fine if we always write
#include <ql/qldefines.hpp>
#include <algorithm>
but what if one forgets and writes
#include <algorithm>
#include <ql/qldefines.hpp>
Should we rely on inclusion order to make it work? Hmm...
>Since defining min()/max() macros is wrong (should have been _min or MIN if
>any), I think it's best to turn it off completely and replace it with
>template functions. That way it should not break anything (and if something
>breaks there will be some very good reason...). Thats why M$ added NOMINMAX.
>
>Of course, using (min)() prevents macro expansion, so you can go with that,
>if you are sure that you (and all of your colleagues now and forever) will
>use (min)() properly...
That should be ensured by using the QL_MIN and QL_MAX macros which expand
to the right definition depending on the compiler. In the VC++ case, they
expand to std::_cpp_min and std::_cpp_max which are the template min and
max we all know and love.
>Why not having a site specific include file that you will use in all of your
>projects?
We have it already. That is the purpose of qldefines.hpp.
Bye,
Luigi