>template <>
class foo<int>
{
public:
static void someFunc() { // Compiler should throw error: No, no,
please not type "int"!!! }
}
See the compile-time assert in Alexandrescu's Loki library,
which is nicely explained in in his _Modern C++ Design_.
(
http://erdani.org).
Alternatively, look at Boost's BOOST_STATIC_SEARCH.
>
Templates represent a kind of macro mechanism built into the C++
language. What you try to do is against the 'spirit' of templates.
It's the user's task to decide whether a template instantiation is
appropriate or not. You shouldn't be patronizing.
Patronization and helpfulness are two different things. Almost
all templates expect their type parameters to provide certain
capabilities, but the C++ language does not currently support
type "contracts". A deliberate error message generated with a
compile-time assertion is almost always better than a
automatically generated template instantiation error. Even
worse, some templates will instantiate but yield incorrect code
for particular types whose error won't be apparent until
run-time. I prefer to catch my errors as soon as possible.
Glen Dayton