What exactly are you trying to do? And what is it that I suggested?
If you mean I suggested rationals, then... that's CS101 and not really a suggestion as such. I can see why you'd want to template rationals (to allow different integer types) but why the policies?
Also I can't quite understand what you are trying to say in your description of your problem, and much less why the policy is templated itself?
Code: Select all
rational<int, template<typename T> checks::default_value<T, 22> > x;
That won't work in a nice way. What you are trying to define here is a variable of type that is a specialization of rational on a template.
Is the idea that you have policies that are parameterized over the type of rational they are applied to? I believe one way to get what you are trying to do (without necessarily agreeing that doing so is a good idea) is to parameterize the class default_value, and the type separately?
You could parameterize default_value for the integer only, and then parameterize it's methods for the type, and have the policy be perfectly normal typename template parameter?
Code: Select all
template <int v>
class default_value {
template <class T>
static T getvalue() {
return (T) v;
}
};
template <class int_t, class policy>
class rational {
...
policy::getvalue();
...
};
rational<int, default_value<22> > x;
Why doesn't that work?
Alternative method would be to define policies as classes with an inner class parameterized over the type, in which case your rational can create such an inner class in a given policy class to the get the specializations.
Maybe there's other possibilities. I've forgotten a lot about templates since it's been a while since I did any non-trivial hackery with them.. plus the specs (especially as implemented) keep changing...
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.