[Variant] Sorting data out of a vector of variant
Hi all!
I have some class with a member which is a vector of boost.variant, i.e.
class Example
{
public:
std::vector
class Example { public: std::vector
> content; } I want to add three members to my class that are vectors of pointers to the specific content items
class Example { public: std::vector
> content; std::vector<typeA> *contentA; std::vector<typeB> *contentB; std::vector<typeC> *contentC; }
Now the question: how can I iterate through the vector content whilst adding its items to the other 3 vectors depending on their type? I know there has to be some way using the apply_visitor functor, but I just don't see how exactly...
// untested pseudo-code
struct segregator : boost::static_visitor<>
{
segregator(vector &contentA, etc for all the types) : contentA_(contentA),
etc for all the types
{}
void operator()(const typeA &a) const
{
contentA_.push_back(a);
}
// etc for all the types
private:
vector<typeA> &contentA_;//etc for all the types
};
int main()
{
typedef variant
participants (2)
-
Igor R
-
Oliver Rudolph