Consider the following class:
template <typename T, T value>
struct C {};
I need to distinguish between 'value == 0' and 'value != 0', which
should be handled at compile time, so I either need a specialized
version for 'value == 0', or require value-to-type mapping. Is there
any way to do this?
The following code doens't seem valid:
template <typename T>
struct C<T,0> {};
at least my compiler tells it isn't (Borland C++ 5.4: Partial
specializations
may not specialize dependent non-type parameters), and I assume it's
right (didn't check the standard, because that won't change my compiler).
I spend several hours last night finding a solution, and every time I came
close, the compiler (also GCC) would *on it. The one thing I can
detect with value to type mapping is when (in the example) 'value == 0',
but not when 'value != 0'.
One thing: a theoretical solution won't be good enough. That is, I actually
have use for it :). Specialization within template classes is not supported,
which I think could do the trick with something like:
template <typename T> struct Map {
template <T> struct Value {
typedef long Type;
};
template <> struct Value<0> {
typedef short Type;
};
and then implement some function for 'long' and 'short', but alas, theQuote:};
compiler doesn't like it...
[real-life example:
template <class Implementor, class PropertyTraits, class CallbackPolicy,
typename CallbackPolicy::template CallPolicy<Implementor,
PropertyTraits>::GetMethodPtr
getMethod,
typename CallbackPolicy::template CallPolicy<Implementor,
PropertyTraits>::SetMethodPtr
setMethod>
class Property {};
I need to detect when getMethod and/or setMethod are 0.
]
TIA,
Geurt
[ about comp.lang.c++.moderated. First time posters: do this! ]