[boost-users] anyways to flatten a stl container.

Is their some kind of method to flatten a stl container... example [[1, 4], [a,b, c], [b, [e]] ] becomes [1, 4, a, b, c, b, e]

Hi, I am wondering how your example container looks like, since it seems to contain several types. If container is a container containing containers with values, you could do something like this: [code] vectorcontainer::value_type::value_type flattened; for(container::iterator it = c.begin(), end = c.end();beg != end; ++it) flattened(it->begin(), it->end(), std::back_inserter(flattened)); [/code] Regards, Vinzenz chun ping wang schrieb:
Is their some kind of method to flatten a stl container...
example [[1, 4], [a,b, c], [b, [e]] ] becomes [1, 4, a, b, c, b, e]
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Oops, some typos here. Vinzenz 'evilissimo' Feenstra schrieb:
Hi,
I am wondering how your example container looks like, since it seems to contain several types.
If container is a container containing containers with values, you could do something like this:
[code] vectorcontainer::value_type::value_type flattened; for(container::iterator it = c.begin(), end = c.end();beg != end; ++it) flattened(it->begin(), it->end(), std::back_inserter(flattened)); [/code] Should be: [code] std::vectorcontainer::value_type::value_type flattened; for(container::iterator it = c.begin(), end = c.end();beg != end; ++it) std::copy(it->begin(), it->end(), std::back_inserter(flattened)); [/code]
Regards, Vinzenz
chun ping wang schrieb:
Is their some kind of method to flatten a stl container...
example [[1, 4], [a,b, c], [b, [e]] ] becomes [1, 4, a, b, c, b, e]
Sorry for the mistake. Regards, Vinzenz

hmm it could be container of any type (set, multiset, list, vector, array,
deque).
It should act like ruby on rails, flatten.
http://www.ruby-doc.org/core/classes/Array.html#M002241
On 10/22/07, Vinzenz 'evilissimo' Feenstra
Oops, some typos here.
Vinzenz 'evilissimo' Feenstra schrieb:
Hi,
I am wondering how your example container looks like, since it seems to contain several types.
If container is a container containing containers with values, you could do something like this:
[code] vectorcontainer::value_type::value_type flattened; for(container::iterator it = c.begin(), end = c.end();beg != end; ++it) flattened(it->begin(), it->end(), std::back_inserter(flattened)); [/code] Should be: [code] std::vectorcontainer::value_type::value_type flattened; for(container::iterator it = c.begin(), end = c.end();beg != end; ++it) std::copy(it->begin(), it->end(), std::back_inserter(flattened)); [/code]
Regards, Vinzenz
chun ping wang schrieb:
Is their some kind of method to flatten a stl container...
example [[1, 4], [a,b, c], [b, [e]] ] becomes [1, 4, a, b, c, b, e]
Sorry for the mistake. Regards, Vinzenz
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

..and how do u intend to create a container that stores any container(
set, multiset ,list, vector..... ) in C++ , if u really want stuff
like Ruby ....take a look at boost::variant ( already known types of
containers to store in a container ) , or boost::any ( unknown
container types to be stored in a container )
HTH
Digz
On 10/23/07, chun ping wang
hmm it could be container of any type (set, multiset, list, vector, array, deque).
It should act like ruby on rails, flatten.
http://www.ruby-doc.org/core/classes/Array.html#M002241
On 10/22/07, Vinzenz 'evilissimo' Feenstra
wrote: Oops, some typos here.
Vinzenz 'evilissimo' Feenstra schrieb:
Hi,
I am wondering how your example container looks like, since it seems to contain several types.
If container is a container containing containers with values, you could do something like this:
[code] vectorcontainer::value_type::value_type flattened; for(container::iterator it = c.begin(), end = c.end();beg != end; ++it) flattened(it->begin(), it->end(), std::back_inserter(flattened)); [/code] Should be: [code] std::vectorcontainer::value_type::value_type flattened; for(container::iterator it = c.begin(), end = c.end();beg != end; ++it) std::copy(it->begin(), it->end(), std::back_inserter(flattened)); [/code]
Regards, Vinzenz
chun ping wang schrieb:
Is their some kind of method to flatten a stl container...
example [[1, 4], [a,b, c], [b, [e]] ] becomes [1, 4, a, b, c, b, e]
Sorry for the mistake. Regards, Vinzenz
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Digvijoy Chatterjee wrote:
...and how do u intend to create a container that stores any container( set, multiset ,list, vector..... ) in C++ , if u really want stuff like Ruby ....take a look at boost::variant ( already known types of containers to store in a container ) , or boost::any ( unknown container types to be stored in a container )
HTH Digz
On 10/23/07, chun ping wang
wrote: hmm it could be container of any type (set, multiset, list, vector, array, deque).
It should act like ruby on rails, flatten.
If you are looking for a function to flatten any STL container [of STL
containers [etc]], the code below will work. (It works under VS 2003.)
It may need cleaning up, and incorrect usage may generate horrid
error messages. There are some test functions at the end.
David
#include <vector>
#include <deque>
#include <list>
#include <cassert>
#include
participants (4)
-
chun ping wang
-
David Walthall
-
Digvijoy Chatterjee
-
Vinzenz 'evilissimo' Feenstra