Argument:
Templates are a mechanism for type creation. A class template creates
what we may think of as a data type through the instantiation of a class
template. A function template creates what we may think of as a function
type through the instantiation of a function template.
Yet while we can pass class templates to both class templates and
function templates as a template parameter, we can not pass function
templates to either class templates or function templates as a template
parameter. This seems like an anomaly of the C++ template specification.
So I am curious in knowing why this anomaly exists, and whether this has
ever been discussed by the C++ standard committee in any way.
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp...@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Function pointers are possible as template arguments because they're
symbols, template functions are not.
What do you mean by "symbol" ?
A function pointer can be a non-type template argument. What has that
do with a "symbol" ?
Why is a class template not a "symbol" but a function template is a "symbol" ?
No. Instantiation of a function template yields a function, not a
function type. Now, that function has a type, but that's a minor part
of the issue. And in C++0x, you could actually pass a template alias
that resolves to a function type if you want that:
template <typename Arg>
using FunctionType = void (Arg);
template <template <typename> class FnTypeGenerator>
class foo {
FnTypeGenerator<int> *intFunctionPointer;
FnTypeGenerator<float> *floatFunctionPointer;
};
>
> Yet while we can pass class templates to both class templates and
> function templates as a template parameter, we can not pass function
> templates to either class templates or function templates as a template
> parameter. This seems like an anomaly of the C++ template specification.
> So I am curious in knowing why this anomaly exists, and whether this has
> ever been discussed by the C++ standard committee in any way.
There are no non-type template parameters of function types, and there
are no non-type template template parameters at all. Therefore, you
cannot pass function templates as arguments to templates.
Sebastian
Because they have linkage.