Re: Operator conversions?
"Robby" <Robby@discussions.microsoft.com> wrote in message
news:D51C4896-7587-40F2-A65D-5A7413B1F5AD@microsoft.com
Please consider the following code:
=======================================
bool components::returnConnectionType(int i_MemLoc1, int i_MemLoc2,
TCHAR *szOperator, int iCF1,
int iCF2, IO *io ) const
{
bool bReturnV = false;
if(iCF1 == -77 && iCF2 == -77) {
if (io->getINT_INTERNAL_VALUE_IMT(i_MemLoc1) == //Always use the
"==" io->getINT_INTERNAL_VALUE_IMT(i_MemLoc2))
bReturnV = true; else bReturnV = false; }
else if (iCF1 >= 0 && iCF2 == -77) {
if (i_MemLoc1 == io->getINT_INTERNAL_VALUE_IMT(i_MemLoc2)) //Use
"==" bReturnV = true; else bReturnV = false; }
//else if repeated seven more times.....
... other code ....
return bReturnV;
===============================================
the "else if" continues for another seven times and it must always
use the "==" operator for every nested "if" line.
My problem is that, I need the same 9 "else if's" satements for all
the other operators such as "<=", ">=", "<", ">" and so forth.....
Try something like this:
template <typename Pred>
bool components::returnConnectionType(
int i_MemLoc1, int i_MemLoc2, int iCF1, int iCF2, IO *io,
Pred pred) const
{
bool bReturnV;
if(iCF1 == -77 && iCF2 == -77) {
bReturnV = pred(
io->getINT_INTERNAL_VALUE_IMT(i_MemLoc1),
io->getINT_INTERNAL_VALUE_IMT(i_MemLoc2));
} else if {...}
}
c.returnConnectionType(..., std::equal<int>());
c.returnConnectionType(..., std::greater<int>());
c.returnConnectionType(..., std::less<int>());
c.returnConnectionType(..., std::greater_equal<int>());
....
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925