[ create a new paste ] login | about

Link: http://codepad.org/2f63mxfZ    [ raw code | fork ]

C++, pasted on Jul 30:
#ifndef DIVIDE_HPP_INCLUDED
#define DIVIDE_HPP_INCLUDED

template <typename T, typename Policy>
T divide(T a, T b, const Policy& pol)
{
	if (b == 0) {
		return policies::raise_domain_error("divide(a, b)", 
			"Cannot divide by zero", 
			T(0),   // Value to be returned  
			pol  // Our policy
		);
	}
	
	return a / b;
}

template <typename T>
inline T divide(T a, T b)
{
	return divide(a, b, policies::default_domain_policy());
}

#endif


Create a new paste based on this one


Comments: