Boost logo

Boost :

Subject: Re: [boost] different matrix library?
From: joel (joel.falcou_at_[hidden])
Date: 2009-08-17 09:54:18


DE wrote:

> e.g. a symmetric matrix can have such an interface:
>
> template<...> //parameters omitted for simplicity
> class symmetric_matrix : public symmetric_matrix_expression<...>
> {
> //...
> explicit symmetric_matrix(size_t size); //since it is square
> //... //there's no need for
> void resize(size_t size); //distinct rows/columns
> //etc... //numbers
> }
>
> so a user will not even be able to write such nonsensical code like
>
> symmetric1.resize(10, 10); //note unnecessary duplication
>
First, concrete inheritance like this == bad performances. Use CRTP
I'm against the proliferation of such types cause it'll just pollute and
clutter
the namespace when a simple policy things is easy to do and have same
set of features.

And anyway, your exampel is faulty, you should ask your user to wait for
any type T that is a matrix expression with symmetric features
or when you'll call f( a+b*c ); you'll get spurious copy.

so the actual generic way to write this should be :

template<class T>
typename enable_if_c< as_matrix<T>::value
                                     && is_same< settings<T,shape>,
symmetric>::value
>::type
f( T const& m );

but we can't have user write that so a small macro thingy will be needed.

> because symmetric_matix does not even provide such interface
> and will not leave user wandering if he missed the key and typed '(10, 19)'
> with unreadable compiler error somewhere in instantiated templates
> as far as i know policies can not do this unless it is full
> specialized and the latter i think is equivalent to a distinct type
>
You should read and learn about : SFINAE ,boost::enable_if and
BOOST_MPL_ASSERT.
That's ages that cryptic error messages int empalte are no more.

-- 
___________________________________________
Joel Falcou - Assistant Professor
PARALL Team - LRI - Universite Paris Sud XI
Tel : (+33)1 69 15 66 35

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk