#include <iostream>
using namespace std;
template < typename T>
struct identity { typedef T type; } ;
template < typename T>
using identity_t = typename identity< T> :: type ;
template < typename X>
void debugValidateParameter( X aValueToCheck, identity_t< X> aLowerLimit, identity_t< X> aUpperLimit)
{
if ( ( aValueToCheck > aUpperLimit) || ( aValueToCheck < aLowerLimit) )
{
cout << "ERROR: ValidateParameters, aValueToCheck = " << aValueToCheck << ", aLowerLimit= " << aLowerLimit << " , aUpperLimit= " << aUpperLimit << endl;
//throw(std::out_of_range("Invalid Range"));
}
}
int main( ) {
unsigned int a = 50 ;
debugValidateParameter( a, 0 , 100 ) ;
debugValidateParameter( a, - 100 , 100 ) ; // Validation will fail UNINTENTIONALLY, since -100 is implicitly converted to unsigned int which becomes a very large positive value
int b = - 50 ;
debugValidateParameter( b, 0 , 100 ) ;
debugValidateParameter( b, - 100 , 100 ) ; // Validation will fail intentionally
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCnRlbXBsYXRlPHR5cGVuYW1lIFQ+CnN0cnVjdCBpZGVudGl0eSB7IHR5cGVkZWYgVCB0eXBlOyB9OwoKdGVtcGxhdGU8dHlwZW5hbWUgVD4KdXNpbmcgaWRlbnRpdHlfdCA9IHR5cGVuYW1lIGlkZW50aXR5PFQ+Ojp0eXBlOwoKdGVtcGxhdGU8dHlwZW5hbWUgWD4Kdm9pZCBkZWJ1Z1ZhbGlkYXRlUGFyYW1ldGVyKCBYIGFWYWx1ZVRvQ2hlY2ssIGlkZW50aXR5X3Q8WD4gYUxvd2VyTGltaXQsIGlkZW50aXR5X3Q8WD4gYVVwcGVyTGltaXQpCnsKICAgaWYoIChhVmFsdWVUb0NoZWNrID4gYVVwcGVyTGltaXQpIHx8IChhVmFsdWVUb0NoZWNrIDwgYUxvd2VyTGltaXQpICkKICAgewogICAgICBjb3V0IDw8ICJFUlJPUjogVmFsaWRhdGVQYXJhbWV0ZXJzLCBhVmFsdWVUb0NoZWNrID0gIiA8PCB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