Complex problem with c++ templates
Posted: Mon Apr 30, 2007 2:18 pm
I've been messing with in particular using template template parameters to specify policy for a class. I've created a rational class (as per Mystran's suggestion elsewhere) for holding rational variables and I've added a policy that allows you to determine what to happen when you try to convert it to a different value type before the programs creates a crash condition (divide by 0, overflow, those things). I've added a do_nothing class (templatized on the type), a create_exception_on_divide_by_zero_attempt and I'm trying to create a default_value class, but I can't figure out how to pass it to the class.
The code that contains the problem:
What do I put at ???? to pass a partial specialization of default_value? I've tried
but GCC tripped over the T.
If I could make a template typedef you could do
but template typedefs don't exist.
Anybody?
The code that contains the problem:
Code: Select all
template <typename int_t> class empty_policy {};
template <typename int_t, int value> class default_value {};
template <typename int_t, template <typename> class policy>
class rational {};
int main() {
rational<int, ???? > x;
}
Code: Select all
rational<int, template<typename T> checks::default_value<T, 22> > x;
If I could make a template typedef you could do
Code: Select all
typedef template <typename T> checks::default_value<T, 22> default_value_of_22;
rational<int, default_value_of_22> x;
Anybody?