# Template with boost::operators extremely verbose and repeating

I got the following ugly code:

template < class _Coeff,
unsigned _nVars,
typename _Expo=int,
template <class, class> class _Map = _Map >
class Polynomial
: boost::ring_operators< Polynomial<_Coeff,_nVars,_Expo,_Map>
std::pair< std::array<_Expo,_nVars>, _Coeff >
, boost::subtractable  < Polynomial<_Coeff,_nVars,_Expo,_Map>, _Coeff
, boost::subtractable  < Polynomial<_Coeff,_nVars,_Expo,_Map>,
std::pair< std::array<_Expo,_nVars>, _Coeff >
, boost::multipliable  < Polynomial<_Coeff,_nVars,_Expo,_Map>, _Coeff
, boost::multipliable  < Polynomial<_Coeff,_nVars,_Expo,_Map>,
std::pair< std::array<_Expo,_nVars>,_Coeff >
> > > > > > > {


In particular, I hate to repeat Polynomial<_Coeff,_nVars,_Expo,_Map>. Is there a way to improve this syntax without using the preprocessor ? I can't manage to get any help from the using keyword here.

Just for the infos: I'm writing multivariate polynomials where _Coeff is the class of the coefficients and the terms X1^4x2^4 are represented as std::array<_Expo,_nVars>.

Easy, with default template arguments:

template < class _Coeff,
unsigned _nVars,
typename _Expo=int,
template <class, class> class _Map = _Map
typename Poly = Polynomial<_Coeff,_nVars,_Expo,_Map>,
typename Pair = std::pair< std::array<_Expo,_nVars>, _Coeff > >
class Polynomial
: boost::ring_operators< Poly
, boost::subtractable  < Poly, _Coeff
, boost::subtractable  < Poly, Pair
, boost::multipliable  < Poly, _Coeff
, boost::multipliable  < Poly, Pair
> > > > > > > {

• I don't like it that much because it expose non-sensical parameter to the user. But then I can re-hide them by a front-end using template... OK ! – hivert Mar 26 '14 at 7:03
• @hivert Indeed I, would also name this Polynomial_Impl or something, then add a template alias to this. The remaining default template arguments would go to the interface, not the implementation. – iavr Mar 26 '14 at 9:05
• Add a std::enable_if at the end to check the user did not change those extra parameters – Manu343726 Jan 26 '15 at 17:40