Reputation: 3486
The code below taken from here (and modified a bit) produce the following error message using g++ compiler: error: template declaration of 'typedef' /RangeChecks.hpp:145:12: error: 'IsInRange' does not name a type
here are the relevant parts from my RangeChecks.hpp file:
class GreaterEqual
{
public:
template <class T>
static bool Compare (const T& value, const T& threshold)
{
return !(value < threshold); /* value >= threshold */
}
};
class LessEqual
{
public:
template <class T>
static bool Compare (const T& value, const T& threshold)
{
return !(value > threshold); /* value <= threshold */
}
};
template <class L, class R, class T>
bool IsInRange (const T& value, const T& min, const T& max)
{
return L::template Compare<T> (value, min) && R::template Compare<T> (value, max);
}
typedef IsInRange< GreaterEqual , LessEqual > isInClosedRange;
I searched over the internet for an answer and there are simular things but non of them, that i found, solved my problem.
Upvotes: 0
Views: 78
Reputation: 14721
IsInRange
is a function, not a type. The easiest way to do what you want to do is to write a wrapper:
template<class T>
bool isInClosedRange(const T& value, const T& min, const T& max) {
return IsInRange<T, GreaterEqual, LessEqual>(value, min, max);
}
Upvotes: 4
Reputation:
IsInRange
is a function template, not a class template, so an instantiation of it is not a type, so you can't create a typedef for it.
Upvotes: 3