In this video, I'd like to go over some of the basics
of the standard template library containers.
We won't go over the details of specific containers in this video,
we'll get to that soon enough.
Instead, it's important to understand what the containers have to offer
as far as functionality is concerned
and understand what types of elements we can store in them.
First, we know that the stl containers are data structures
that can store almost any type of object,
and they're implemented as template-based classes.
Each container has a set of member functions that we can use.
Some of these member functions are specific to a particular container.
But there are quite a few member functions that all containers implement.
We'll go over a table with some of these methods in the next few slides.
Finally, each container has an associated header file
that must be included in order to use the container.
We've already seen this with vector and string.
I'll tell you what the specific header files are for each container class we go over.
Okay. So let's take a look at some of the common methods
provided by the stl containers.
This table and the table on the next slide
show some of the functionality provided by the stl containers.
Let's start with the default constructor.
All containers provide default constructors,
and it results in an empty container.
They also provide many versions of overloaded constructors
that allow you to initialize the containers in many ways.
You have to refer to the specific container you want to use to see the various overloaded constructors.
Containers also provide copy and move constructors.
So we can create a new container based on an existing container.
We can choose to copy it or move it.
Of course, containers provide destructors.
The container destructors clean up the container and delete all the objects in it.
Containers also provide copy and move assignment.
This, of course, will allow you to copy or move an existing container
into another existing container.
Remember, this is not initialization.
And containers provide the last three methods in the table,
which are used very often.
Size returns the number of elements in the container,
empty returns true or false depending on whether the container is empty or not,
and the insert method allows us to insert an element into a container.
In this table, we can see that we also have the ability to compare two containers.
We can test to see if the elements of one container
are less than the elements of a second container.
And we can also test for less than or equal to greater than and greater than or equal to.
We can also check to see if the contents of two containers are the same or not,
using the equality operators
We have the swap function, which swaps two containers.
And we can remove one or all elements from a container, using erase and clear.
And finally, we can get iterators to elements in containers.
Not all containers support all these iterators,
but I listed them anyway so you could see them here.
We'll talk about iterators in more detail in the next video. So don't worry,
you'll learn about them in a few minutes.
This last slide is super important.
Now that we know a little bit more about the functionality provided by containers,
let's talk about what types of objects we can store in containers.
First, we can store all of the primitive types in containers,
int, float, double, all of them.
But what about our objects.
It's important to remember that when we store an element in a container
the container makes a copy of that element.
So we must be sure that our objects are copyable and assignable.
This means they must have default copy constructors
or our own copy constructors as well as copy assignment.
We can also provide move semantics for efficiency.
Finally, the ordered associative containers must be able to compare objects.
They do this using the less than and the equality operators.
So your objects must support these operators via operator overloading.
Okay. I hope you can see that everything we've learned and done in this
course comes together right here.
We now know exactly what we have to do to make our own objects work with the stl.
And you know what it's not that complicated. In most cases,
we can use all of the compiler provided functionality
unless we have raw pointers,
and we already learned how to handle classes with raw pointers.
Well, that completes this video. In the next video, we'll learn about iterators,
which give us something to do with these containers. I'll see you there.