Re: template specialization problems
On 6 Nov., 20:01, Nikola Smiljani? <popiz...@gmail.com> wrote:
I have this member function:
template <typename T, bool>
void connect_real(T* p, R (T::*func)(T1));
Are R/T1 typedefs or another template parameter? In the
following I assume they represent known, but arbitrary
types.
and I would like to specialize it for both values of true and false
and call it like this:
connect_real<T, std::tr1::is_base_of<trackable, T>::value>(p, func);
where p is T* and func is T member function R (T::*func)(T1)
I cant say:
template <>
void connect_real<true>
because I need my T type, and if I say something like:
template <typename T, bool>
void connect_real<T, true>
I get: illegal use of explicit template arguments
Right, function templates do not support partial
specialization, they give you explicit specialization
and overloading.
I suggest that you solve your problem by means of
a partially specialized class template which is
invoked by a single function template like this:
template <typename T, bool Trackable>
struct ConnectReal; // Not defined.
template <typename T>
struct ConnectReal<T, true> {
static void evaluate(T* p, R (T::*func)(T1)) {
/* whatever */
}
};
template <typename T>
struct ConnectReal<T, false> {
static void evaluate(T* p, R (T::*func)(T1)) {
/* whatever */
}
};
template <typename T, bool Trackable>
inline void connect_real(T* p, R (T::*func)(T1)) {
ConnectReal<T, Trackable>::evaluate(p, func);
}
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]