I have a static Utils class. I want certain methods to be templated, but not the entire class. How do I do this?
This fails:
#pragma once
#include <string>
using std::string;
class Utils
{
private:
template<class InputIterator, class Predicate>
static set<char> findAll_if_rec(InputIterator begin, InputIterator end, Predicate pred, set<char> result);
public:
static void PrintLine(const string& line, int tabLevel = 0);
static string getTabs(int tabLevel);
template<class InputIterator, class Predicate>
static set<char> Utils::findAll_if(InputIterator begin, InputIterator end, Predicate pred);
};
Error:
utils.h(10): error C2143: syntax error : missing ';' before '<'
utils.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
utils.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
utils.h(10): error C2238: unexpected token(s) preceding ';'
utils.h(10): error C2988: unrecognizable template declaration/definition
utils.h(10): error C2059: syntax error : '<'
What am I doing wrong? What is the correct syntax for this?
Incidentally, I'd like to templatize the return value, too. So instead of:
template<class InputIterator, class Predicate>
static set<char> findAll_if_rec(InputIterator begin, InputIterator end, Predicate pred, set<char> result);
I'd have:
template<class return_t, class InputIterator, class Predicate>
static return_t findAll_if_rec(InputIterator begin, InputIterator end, Predicate pred, set<char> result);
How would I specify that:
1) return_t must be a set of some sort
2) InputIterator must be an iterator
3) InputIterator's type must work with return_t's type.
Thanks.