|
Boost : |
From: Bradford, Chase (CHASE.BRADFORD_at_[hidden])
Date: 2008-07-24 16:24:34
The following example shows how to use some of the interface for the
class. The container is a basically a map of variants, but internally
it holds variant<vector<T1>, vector<T2>, ...>.
The result is a container that provides access to individual fields for
fast processing in parallel. The list of fields is growable, because
that was one of the requirements for the program I'm working on. I'm
not sure that's a good feature to have in general though.
Chase
template<class Key, class Variant> class basic_soa;
int main()
{
typedef basic_soa<std::string, boost::variant<int, float> > MySoa;
MySoa s;
// Make internal vectors hold 100 elements.
s.resize(100);
// Create a fields named x and y. This sort of makes the object a
// container of 2D points.
s.add_field<float>("x");
s.add_field<float>("y");
fill( s.field<float>("x").begin(), s.field<float>("x").end(), rand);
fill( s.field<float>("y").begin(), s.field<float>("y").end(), rand);
float x_sum = 0.0f;
float y_sum = 0.0f;
// Inefficiently work over the slices
for( MySoa::iterator iter=s.begin(); iter != s.end(); ++iter )
{
x_sum += iter->get<float>("x");
y_sum += iter->get<float>("y");
}
// Add a new field for numbering the points.
s.add_field<int>("index");
// Apply indexing by slice
for( size_t i=0; i<s.size(); ++i )
{
// This is also inefficient.
s[i].get<int>("index") = i;
}
// Redo the indexing by only accessing the "index" field.
std::vector<int>& indexes = s.get_field<int>("index");
for( size_t i=0; i<indexes.size(); ++i )
{
indexes[i] = i;
}
}
-----Original Message-----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of vicente.botet
Sent: Thursday, July 24, 2008 10:47 AM
To: boost_at_[hidden]
Subject: Re: [boost] generict container for structure of arrays
----- Original Message -----
From: "Alp Mestan" <alpmestan_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, July 24, 2008 7:11 PM
Subject: Re: [boost] generict container for structure of arrays
>
> Seeing a sample would be fine.
>
yes this can help.
Vicente
_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk