Boost logo

Boost Users :

From: Rodney.Schuler_at_[hidden]
Date: 2001-12-14 11:04:21


I saw the boost preprocessor library and I thought that
BOOST_PREPROCESSOR_MIN might help solve a problem in some code that I am
maintaining. This code has the naive implementation of MIN and MAX:
#define MIN(a,b) ((a)<(b)?(a):(b))
This code also has many (tens of thousands!) of places where a function
calls are used as arguments to MIN and MAX like this:
foo=MIN(func(args1),func(args2))
The function called is a very long running function. The performance hit
taken by three evaluations of the function is a problem I am working to
fix. I know the best solution is to add some local variables, and store
the results of the functions in them, then use MIN on the local vars. But
I'd like to get some Idea of how much performance increase I am likely to
get by crawling through the code and fixing all the occurrences of
MIN(func(args1),func(args2))

Wondering if BOOST_PREPROCESSOR_MIN had a way to make only two evaluations
of func I wrote:

#include <iostream>
#include <boost/preprocessor/min.hpp>

using std::cout;
using std::endl;

int func(int i)
{
    cout << " func called " << i << endl;
    return i;
}

int main ()
{
    cout << "result " << BOOST_PREPROCESSOR_MIN(func(1),func(2)) << "\n"
<< endl;
    cout << "result " << BOOST_PREPROCESSOR_MIN(func(4),func(3)) << "\n"
<< endl;
    return 0;
}

And my compilers (MSVC 5 sp3 and MSVC 6 sp5) responded thusly:

C:\temp\boostminvc5\main.cpp(15) : error C2065:
'BOOST_PREPROCESSOR_IF_BOOLBOOST_PREPROCESSOR_BOOLBOOST_PREPROCESSOR_IF_BOOLBOOST_PREPROCESSOR_BOOLBOOST_PREPROCESSOR_NOR_BOOLBOOST_PREPROCESSOR_BOOLBOOST_PREPROCESSOR_ADDBOOST_PREPROCESSOR_SUBfunc'

:
undeclared identifier
C:\temp\boostminvc5\main.cpp(15) : error C2065:
'BOOST_PREPROCESSOR_SUBfunc' : undeclared identifier
C:\temp\boostminvc5\main.cpp(15) : error C2146: syntax error : missing ';'
before identifier
'BOOST_PREPROCESSOR_BOOLBOOST_PREPROCESSOR_ADDBOOST_PREPROCESSOR_SUBfunc'
C:\temp\boostminvc5\main.cpp(15) : error C2065:
'BOOST_PREPROCESSOR_BOOLBOOST_PREPROCESSOR_ADDBOOST_PREPROCESSOR_SUBfunc' :
undeclared identifier
C:\temp\boostminvc5\main.cpp(15) : error C2065:
'BOOST_PREPROCESSOR_NOR_BOOLBOOST_PREPROCESSOR_BOOLBOOST_PREPROCESSOR_SUBfunc'

: undeclared identifier
C:\temp\boostminvc5\main.cpp(15) : error C2146: syntax error : missing ')'
before identifier 'BOOST_PREPROCESSOR_BOOLBOOST_PREPROCESSOR_SUBfunc'
C:\temp\boostminvc5\main.cpp(16) : error C2146: syntax error : missing ';'
before identifier
'BOOST_PREPROCESSOR_BOOLBOOST_PREPROCESSOR_ADDBOOST_PREPROCESSOR_SUBfunc'
C:\temp\boostminvc5\main.cpp(16) : error C2146: syntax error : missing ')'
before identifier 'BOOST_PREPROCESSOR_BOOLBOOST_PREPROCESSOR_SUBfunc'

First, this is a bug report.

Second, can anybody answer my question does BOOST_PREPROCESSOR_MIN get
around the unnecessary evaluations problem?

Thanks
-Rodney
Rodney.Schuler_at_[hidden]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net