
Wouldn't a vector of boost::any act like that ? On 7/24/08, Bradford, Chase <CHASE.BRADFORD@saic.com> wrote:
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@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of vicente.botet Sent: Thursday, July 24, 2008 10:47 AM To: boost@lists.boost.org
Subject: Re: [boost] generict container for structure of arrays
----- Original Message ----- From: "Alp Mestan" <alpmestan@gmail.com> To: <boost@lists.boost.org> 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 _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Alp Mestan --- http://blog.mestan.fr/ --- http://alp.developpez.com/ --- In charge of the Qt, Algorithms and Artificial Intelligence sections on Developpez