c частичной специализации шаблона функции-члены класса

There do appear to be a few closely related questions, but I'm struggling to work out how to apply their solutions.


I have a traits class, shown below, for manipulating matrices that I am using with (amongst other matrix implementations). I would like to partially specialize just the as shown in the comment, however this fails as functions cannot be partially specialized.


I don't want to partially specialize the struct as this entails the overhead of re-defining all its members. One solution would be to separate each matrix-related function into its own struct, but it would be nice to keep them grouped in the one traits class.

Any ideas? Feel free to comment on the general application of the traits concept as well.

#include <boost/numeric/ublas/matrix.hpp>enum matrix_storage_order {row_major, column_major};template<class matrix_type>struct matrix_traits {  // Default expects c-style row_major storage order.  static matrix_storage_order get_storage_order(const matrix_type& m)  { return row_major; }  // By default can't change storage order so simply transpose.  static void switch_storage_order(matrix_type& m) { m.transpose(); }};namespace ublas = boost::numeric::ublas;/* This doesn't work with error C2244:  * 'matrix_traits<matrix_type>::switch_storage_order' : unable to match function  * definition to an existing declaration  */// template<class value_type>// void matrix_traits<ublas::matrix<value_type> >::switch_storage_order(//     ublas::matrix<value_type>& m) {//   m = boost::numeric::ublas::trans(m);// }typedef boost::numeric::ublas::matrix<double> matrix_double;template<>void matrix_traits<matrix_double>::switch_storage_order(matrix_double& m) {  m = boost::numeric::ublas::trans(m);}template <class matrix_type>void function_requiring_column_major_storage_order(matrix_type& m) {  bool switch_order =    matrix_traits<matrix_type>::get_storage_order(m) == row_major;  if (switch_order) matrix_traits<matrix_type>::switch_storage_order(m);  // ... Do some work on m.  if (switch_order) matrix_traits<matrix_type>::switch_storage_order(m);}int main() {  matrix_double m;  // ... Fill the matrix.  function_requiring_column_major_storage_order(m);}