F
Francesco Montorsi
Hi,
I'm quite new to templates... I was asked to transform the following macro
#define DECLARE_STRING_CHECK(func) \
inline bool func##String(const MyString& val) \
{ \
for ( MyString::const_iterator i = val.begin(); \
i != val.end(); \
++i ) \
if (func(*i) == 0) \
return false; \
return true; \
}
DECLARE_STRING_CHECK(isalpha) // declares isalphaString()
DECLARE_STRING_CHECK(isalnum)
DECLARE_STRING_CHECK(isdigit)
in a template.
I blindly tried:
template<typename T>
inline bool StringCheck(const MyString& val)
{
for ( MyString::const_iterator i = val.begin();
i != val.end();
++i )
if (T(*i) == 0)
return false;
return true;
}
Needless to say it doesn't work. I.e. if I write
if (!StringCheck<isalpha>(str))
return false;
I get "error: no matching function for call to ‘StringCheck(const MyString&)’"
with GCC...
Can you help me with some hints
?
Thanks!!
Francesco
I'm quite new to templates... I was asked to transform the following macro
#define DECLARE_STRING_CHECK(func) \
inline bool func##String(const MyString& val) \
{ \
for ( MyString::const_iterator i = val.begin(); \
i != val.end(); \
++i ) \
if (func(*i) == 0) \
return false; \
return true; \
}
DECLARE_STRING_CHECK(isalpha) // declares isalphaString()
DECLARE_STRING_CHECK(isalnum)
DECLARE_STRING_CHECK(isdigit)
in a template.
I blindly tried:
template<typename T>
inline bool StringCheck(const MyString& val)
{
for ( MyString::const_iterator i = val.begin();
i != val.end();
++i )
if (T(*i) == 0)
return false;
return true;
}
Needless to say it doesn't work. I.e. if I write
if (!StringCheck<isalpha>(str))
return false;
I get "error: no matching function for call to ‘StringCheck(const MyString&)’"
with GCC...
Can you help me with some hints
Thanks!!
Francesco