STL Container of containers

D

Dave Vandervies

Can I have a STL list of lists?

Yep. The STL containers can store any data type, and other containers
are (at least for this purpose) no different from any other data type.

A few typedefs might make the resulting code easier to follow:

typedef std::list<mydata> my_data_list;

void foo(std::list<my_data_list> list_of_lists)
{
/*Do stuff with each list contained list_of_lists*/
}

(For more fun, you can also have, f'rexample, sets of maps of vectors.
typedef gets a *lot* more useful there.)


dave
 
M

Mike Wahler

s said:
Can I have a STL list of lists?

Sure.

std::list<std::list<int> > listoflists;

When 'nesting' the angle brackets like this,
be sure to separate them by whitespace, else
the compiler will think they're a shift operator,
and generate an error.

-Mike
 
J

jeffc

Mike Wahler said:
Sure.

std::list<std::list<int> > listoflists;

When 'nesting' the angle brackets like this,
be sure to separate them by whitespace, else
the compiler will think they're a shift operator,
and generate an error.

Important point!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top