Topic: Function template template parameters
Author: "Terje Slettebx" <miko@nospam.chello.no>
Date: 26 Jan 03 00:09:08 GMT Raw View
Hi.
I've done a search in the archive for this, but haven't found anything, so
therefore I post this.
Does anyone know why function template template parameters aren't allowed?
We have class template template parameters, but not function template
template parameters.
This came up in a discussion at the Boost list (but as language extensions
are off topic for Boost, I took it here), regarding enabling higher order
functional programming with function templates in C++. Specifically, there
was a question about how to iterate over a typelist, calling a function for
each type, and passing a parameter, using the Boost Metaprogramming Library
(MPL).
A solution to this currently involves making a function object, which passes
the call to the required function:
// Function to call for each type
template<class T>
void my_function(std::string &) { ... }
struct function
{
function(std::string &s) : str(s) {}
template <class T>
void operator()(T) const
{
my_function<T>(str);
}
private:
std::string &str;
};
mpl::for_each<my_list>(function(s));
Had function template template parameters existed, you might be able to
collapse this code to one line:
mpl::for_each<my_list, std::string &, function>(s);
It could be defined something like this:
template<class Sequence, class T, template<class> void Function(T)>
void for_each(T);
Is there any specific reason for not allowing this, or is it simply that one
didn't want to delay standardisation?
Regards,
Terje
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]