So lets say I had a function that checked if a number was within a range:
[source lang="java"]bool IsWithin( int32 number, int32 min, int32 max );[/source]
I also wanted it to work with all my base types, such as int64, uint16, float32 etc.
The best bet would be a template right?
It would kinda not be fun to have to constantly do 'IsWithin< type >( var, var, var );' for such ubiquitous code, but I can understand it if that's just the only way.
However, although 'IsWithin' will work for any type that has the operators '<' and '>' defined and is therefore 'safe' what about a function that takes the square root? How can I keep people from just trying 'Sqrt< someclass >( classinstance );'?
I know that would throw a compiler error, but assuming there was a situation with a function that would not? I would like to be able to qualify the acceptable types that a template can be used on in some cases if possible.
Edited by James Leighe, 28 July 2012 - 05:09 PM.







