Boost logo

Boost :

From: James (James.Sutherland_at_[hidden])
Date: 2006-11-06 13:31:32


All,

I am interested in using boost::variant to represent various field types in
a performance-critical piece of software. I need the ability to perform
nontrivial operations on fields, and would like to embed the loop within the
visitor portion of the code for performance reasons.

As a simple example, say I have

> typedef std::vector<double> A;
> typedef std::vector<int> B;
> typedef boost::variant< A, B, ... > FieldVariant;
>
> FieldVariant x, y, z;
> // assign x, y ...
> z = sqrt(x)+x*y+5.38*y^2.0;

Here I could overload the ³+² operator for various types in the
FieldVariant. The overloaded + operator would implement a binary visitor
which would loop over the entries and sum them (remember that the types in
the variant are vectors of objects). The same thing could be done for other
operators. This is highly inefficient, however, since it requires multiple
loops and multiple step assembly of z.

What I would like is a way to compute ³z² in a highly efficient manner. The
binary visitor does not allow this

Is there a good way to extend boost::variant to support efficient operations
as outlined above?

James


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