Re: class template specialization with signed/unsigned type problem
On 8/1/2012 10:04 AM, Blonder wrote:
did you mean something like this? Or what did you mean when you say assume?
template <typename T, typename F>
void ConverterHelper(T t, F f) {}
template <typename T>
void ConverterHelper<>(T t, unsigned long f) {}
template <typename T>
void ConverterHelper<>(T t, long f) {}
<sigh> It's difficult to answer without the context. Perhaps you could
at some point consider quoting the article to which you're replying...
First off, you had
template<class T, class F> class C { ...
bool operator() (T& to, const F& from);
};
to specialize it for 'F == long' or 'F == unsigned long' *in a single
function/class* is rather silly; you end up with lots of 'if' statements
and/or static asserts. So, don't do it. I suggested to specialize
twice, but then call some kind of helper class in which you can assume
that 'long' or 'unsigned long' is the "source" type. BTW, I remember
submitting something on a similar topic to the FAQ. Have you read the FAQ?
template<class T> class CH_long_ulong {
... // some common functionality
// maybe in the form of templates
};
template<class T> class C<T, long> : CH_long_ulong<T> {
public:
bool operator() (T& to, long from) {
CH_long_ulong<T>::common_part1(from);
.. // some special processing for 'long'
CH_long_ulong<T>::common_part2(from);
.. // some more special processing for 'long'
}
};
template<class T> class C<T, unsigned long>
: CH_long_ulong<T> {
public:
bool operator() (T& to, unsigned long from) {
CH_long_ulong<T>::common_part1(from);
.. // some special processing for 'unsigned long'
CH_long_ulong<T>::common_part2(from);
.. // some more special processing for 'unsigned long'
}
};
Hope this helps. Ask more questions.
V
--
I do not respond to top-posted replies, please don't ask