opCmp with double values

kerdemdemir kerdemdemir at gmail.com
Sun Dec 24 10:10:51 UTC 2017


In documentation and forums I found some example for overloading 
opCmp for int values. But I couldn't see any examples for double 
values.

That is what I come up with my own:

struct AdjustableVal ( T = double )
{
	this ( T initVal )
	{
		curVal = initVal;
		initialVal = initVal;
	}
	
	
     int opCmp( T rhs ) const {
         auto diff = curVal - rhs;
         if (  fabs(diff) < 0.00000001 )
             return 0;
         else if ( diff < 0 )
             return -1;
         else
             return 1;
      }

	T curVal;
	T initialVal;
}

Do you guys see any problem with it or any suggestions?
Secondly if the value type(T) does not have "-" operator, is it 
possible to still get my code compiled somehow with static_if?


Erdem


More information about the Digitalmars-d-learn mailing list