list

Hi guys,
I've been seeing this a lot in codes on the website:
1
2
3
...
list<...>
...

and would just like to know what that does. Thanks
The C++ standard library has numerous containers as, for example, std::vector, std::list, std::forward_list, and so on.

They are defined as template classes. For example std::list<int> means a specialization of the template class list for objects of type int.
Last edited on
And would you mind telling me how you use it and what it does?
closed account (j3A5Djzh)
Hi,
some information about list is here:
http://en.wikipedia.org/wiki/List_(abstract_data_type)
Here is a slightly more information on using the C++ STL container list: http://cplusplus.com/reference/stl/list/

And a page about basic use: http://www.cplusplus.com/reference/stl/list/list/
LOOK IT UP. Don't ask us to teach you. Only ask questions once you have found out what it is, and you can ask about specifics of what you can't understand.
@IWishIKnew
No need to be hostile. I quite often ask what something is because either I can't understand material that I read, or I can't find material that satisfactorily explains something to me. I remember when I asked about how a list "technically" works and the base concept of them. It's complicated if you don't know know, and even harder to understand without understanding pointers very well.

@MaxLascombe
The links provided give you a general overview of how to use them and what a list is. The best way to look at it is to think of what it is, a list. You can manipulate the list using an iterator, work directly at the beginning or end of the list, and do some other pretty nifty stuff to them. They're faster than a vector and an array since it's linked together using pointers to point to the next and previous node (doubly linked list).
closed account (zb0S216C)
I'll save you the time and give you a brief overview, because by the judging of the previous posts, it would be more beneficial.

The syntax you posted stems from templates. A template class template isn't a complete type. In order for it to become a complete type, you must instantiate the template class. This takes the same form as syntax as you posted. The types and/or values that sit between the angle brackets are called template-parameters. These parameters are used to fill the data needed to complete the template class template type. For instance:

1
2
3
4
5
template< typename T >
struct Sample 
{
    T Type;
};

Sample is not a complete type, because the type T holds is not yet known. To complete the type, we must instantiate (create an object of) Sample. When we do this, we pass the data the class needs in order for the compiler to complete the type. An analogy would be providing the missing puzzle pieces to complete the puzzle. For example:

 
Sample< int > IntSample;

By specifying int, we've gave the compiler the missing information it needs to instance a Sample. This in fact creates an entirely different type based on int. In other words, if we instantiated Sample with another type, such as double, the compiler would generate another type based on double. In effect, instancing a template twice with two different types would be equivalent to this:

1
2
3
4
5
6
7
8
9
struct Sample // Sample< int >
{
    int Type;
};

struct Sample // Sample< double >
{ 
    double Type;
};

Of course, this code won't compile, since its only to demonstrate what the compiler will see.

Hope this helps, mate :)

Wazzak
Last edited on
Thanks a lot for everything guys!
Topic archived. No new replies allowed.