Boost logo

Glas :

[glas] evaluation and dispatch of functions

From: Karl Meerbergen (Karl.Meerbergen_at_[hidden])
Date: 2005-09-21 10:17:20


Hello,

One of the issues I am thinking about now is how to dispatch a function
to the right piece of code.
For example, norm_2(v), is going to be (slightly) different for dense
and sparse collections and depends on whether we use the blas nrm2()
functions.

At this stage, we already have a collection_type in the dense_vector and
sparse_vector collections, but this might not be enough. I would like to
be able to add a number of attributes in an attribute list in order to
be able to dispatch a function, depending on the attribute.

I think that boost::mpl::list or boost::mpl::vector would be good
candidates to contain a sequence of attributes: these can be
dense_collection_type (or sparse_collection_type), blas_type,
fixed_size_type etc. The function norm_2() interrogates the attributes
in order to know which implementation should be chosen.

If, in addition, we allow the creation of new collection types by adding
atributes to old collection types, and implement the corresponding
implementations for norm_2(), the glas dispatch system should be able to
select a user implementation for this function.

template <class V>
typename norm_2_traits<V, attribute<V>::type>::result_type norm_2( V
const& v ) {
  return norm_2_traits<V, attribute<V>::type>( v ) ;
}

where the norm_2_traits are specialized for each attribute type.

It would also be possible to work out a system with nesting:
the norm_2_traits first looks at the first attribute and passes the
remaining attributes to another instantiation of norm_2_traits, e.g. a
vector having dense_collection_type and blas_type as attributes would
first be dispatched to the dense specialization where it then will be
sent to the dense blas specialization.

For example, a glas user could add an attribute my_attribute to
dense_vector and then use its own implementation for norm_2().

I am working out an example for the 2-norm to make this idea more concrete.

In the meantime I would like to know your opinion about all this.

Best regards,

Karl

-- 
==============================================
Look at our unique training program and
Register on-line at http://www.fft.be/?id=35
----------------------------------------------
Karl Meerbergen
Free Field Technologies
16 place de l'Université
B-1348 Louvain-la-Neuve - BELGIUM
Company Phone:  +32 10 45 12 26
Company Fax:    +32 10 45 46 26
Mobile Phone:   +32 474 26 66 59
Home Phone:     +32 2 306 38 10
mailto:Karl.Meerbergen_at_[hidden]
http://www.fft.be
==============================================