There are ways to restrict the types you can use inside a template you write by using specific typedefs inside your template. This will ensure that the compilation of the template specialisation for a type that does not include that particular typedef will fail, so you can selectively support/not support certain types.
The rationale for why specializations don't participate in overloading is simple, once explained, because the surprise factor is exactly the reverse: The standards committee felt it would be surprising that, just because you happened to write a specialization for a particular template, that it would in any way change ...
Explicit (full) specializationAllows customizing the template code for a given set of template arguments.
A template has only one type, but a specialization is needed for pointer, reference, pointer to member, or function pointer types. The specialization itself is still a template on the type pointed to or referenced.
I start apologising if I am stupid enough to not find the answer if it is so obvious.
I have seen dozens of pages talking about having specific template specialization for pointer parameters.
I'd like to be able, though, of preventing a template to specialize pointer parameters, but I can't figure out how to do this.
template< class T >
void function( T arg )
{
//...
}
int main( )
{
int i = 42;
function( i ); // Ok
function( &i ); // Die bastart with a compiler error!
}
Is it possible?
Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With