The purpose of boost::tuple
is to mix arbitrary types. If, as you say,
I am only inserting integers
then you should use map< int, set< vector< int > > >
. (If I were you, I'd throw some typedef
s at that.)
To answer the original question, though, boost::tuple
doesn't allow arbitrary types at runtime. boost::any
does. However, any
does not support comparison so there's a little more work if you want to use it in a set
.
typedef vector< boost::any > tuple;
struct compare_tuple { bool operator()( tuple const &l, tuple const &r ) const {
assert ( l.size() == r.size() );
for ( tuple::iterator lit = l.begin(), rit = r.begin();
lit != l.end(); ++ lit, ++ rit ) {
assert ( lit->type() == rit->type() );
if ( lit->type() == typeid( foo ) ) { // find the type and perform "<"
return boost::any_cast<foo>(*lit) < boost::any_cast<foo>(*rit);
} else if ( lit->type() == typeid( bar ) ) {
return boost::any_cast<bar>(*lit) < boost::any_cast<bar>(*rit);
} /* etc; you will need to enumerate all the types you can insert */
}
} };
typedef std::map< int, std::set< tuple, compare_tuple > > main_map;