Posted by: sureshamrita | December 19, 2009

A simple illustration on Boost::any

#include <iostream>
#include <vector>

#include <boost/any.hpp>

using namespace
std;
using namespace
boost;

int
main(){

vector<any> v1, v2;

v1.push_back(5);

v1.push_back('a');

v2.push_back(10);

v2.push_back(string("Amma"));

copy(v2.begin(),v2.end(),back_inserter(v1));

for
(vector<any>::size_type i = 0; i < v1.size(); i++){

if
(char * pc = any_cast<char>(&v1[i])) cout << *pc << endl;

else if
(int * pi = any_cast<int>(&v1[i])) cout << *pi << endl;

else if
(string * ps = any_cast<string>(&v1[i])) cout << *ps << endl;
}
}


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: