{"id":251,"date":"2015-09-03T13:20:45","date_gmt":"2015-09-03T10:20:45","guid":{"rendered":"https:\/\/sobbayi.com\/?p=251"},"modified":"2015-09-03T13:20:45","modified_gmt":"2015-09-03T10:20:45","slug":"the-c-standard-template-library-part-1-overview","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/the-c-standard-template-library-part-1-overview\/","title":{"rendered":"The C++ Standard Template Library Part 1- Overview"},"content":{"rendered":"

Today we’re going to talk about the C++ Standard Template Library<\/a> also known as the standard library. C++<\/a> is a very old high-level programming language favored for its performance and power.<\/p>\n

Even though C++ provides the bells and whistles like other high-level programming languages. Like other programming languages, it is not easy to do certain tasks using the core language features. This is why we need a library. C++ comes with a standard library right out of the box. There are other C++ libraries such as C++ Boost and others but they are not considered part of the C++ standard library. At the root of the C++ standard library is the Standard Template Library also referred to as STL.<\/p>\n

The C++ Standard Template Library consists of containers and algorithms. There is one more component that ties these two components of the library together which we refer to as Iterators.<\/p>\n

What are C++ Standard Template Library Containers?<\/h2>\n

C++ Standard Template Library containers are data structures that contain data. Data is not very useful unless it can be accessed or manipulated. The containers in of themselves are not able to do much with the data that they hold without the help of the second component of the C++ Standard Template Library this component is known as Algorithms.<\/p>\n

What are Algorithms?<\/h2>\n

Algorithms in the Standard Template Library are logical functions that operate on the data that is stored in the containers or data structures. Operating on this data may sound trivial enough. The reason is that the data stored in the containers usually have different interfaces.<\/p>\n

The problem here is compounded when you have several algorithms operating on several data structures. The containers may need to leverage the capabilities of several algorithms. On the other hand, the algorithms may need to operate on the different types of data stored in different containers.<\/p>\n

This would be a N*M implementation where N is the number of containers and M is the number of algorithms. To solve this problem, the C++ Standard Template Library provides a module called an Iterator.<\/p>\n

What the Iterators do is they hide the interfaces of the containers from the algorithms. The Algorithm only needs to interact with the Iterators and the Iterators interact with a container. This makes the C++ Standard Template Library more modular. This makes it extendable, easy to maintain and promotes code reuse.<\/p>\n

Here is a code snippet showing the connection between an STL Container, an Iterator, and an Algorithm.<\/p>\n