14 December, 2014

Standard Template Library (STL): An Introduction Part 1

C++

Quite a fascinating language isn't it? But people will swear to it that their lives(especially developers) have been made a lot easier with the use of Libraries.

Today I will be talking about
  • C  Libraries  and  Headers
  • C++ Standard Libraries
    • C++  Libraries  and  Headers
    • C++  Standard  Template  Libraries  and  Headers
  • Boost  C++  Libraries

1.  C++ Standard Libraries

C++ provides a huge set of libraries:
  1. Standard ANSI C library ported over to C++. These libraries are name with a prefix "c" and without the ".h", e.g., <cmath> for C's <math.h><cstdlib> for C's<stdlib.h>, etc.
  2. C++ new Libraries, such as <iostream><iomanip><string><fstream><sstream>.
  3. C++ Standard Template Library (STL): consists of containers, iterators, algorithms and function objects.
  4. Boost C++ libraries.
The cplusplus.com at http://www.cplusplus.com/reference provides a comprehensive online references for the C++ libraries (and updated for C++11).

1.1  C Libraries and Headers

  • <cstring>: To be elaborated later.
  • <cmath>: numeric mathematical library
  • <cstdlib>: General utilities such as Execution (abortexitEXIT_SUCCESSEXIT_FAILURE); Environment (getenv); Dynamic Memory Management (mallocfreecallocrealloc), String Parsing (atoiatofatolstrtod), Pseudo-random sequence generation (randsrandRAND_MAX); Array searching and sorting (bsearchqsort).
  • <cctype>:Checkingcharactertypes (isalphaisdigitisalnumisspaceisupperislowerisblankiscntrlisgraphisprintispunctisxdigit) and character conversion (toupper,tolower).
  • <climits><cfloat>: Size and limit of integer types (INT_MAXINT_MINUINT_MAXCHAR_BIT; and SHRT_XXX for shortLONG_XXX for longLLONG_XXX for long longCHAR_XXX for char) and floating-point types (DBL_MINDBL_MAXDBL_DIGDBL_MIN_EXPDBL_MAX_EXP; and FLT_XXX for floatLDBL_XXX for long double).
  • <ctime>timedifftimeclockgmttimelocaltime, and etc.
  • <cstdio>: C's IO operations (scanfprintffscanffprintffopenfclose, etc)
  • <cassert><cerrno><csignal>: Diagnostics and error
  • <clocale>: localizaton
  • <cstdbool><cstdint><cstddef><cstdarg>:
  • <cuchar><cwchar><cwcchar>: Unicode characters.

1.2  C++ Libraries and Headers

  • <ios><iostream><istream><ostream><fstream><sstream>:
  • <iomanip>:
  • <string>:
  • <regex>:
  • <random>:
  • <limits>:
  • <stdexcept><exception>:
  • <complex><tuple><valarray>:
  • <locale>:
  • <typeinfo>:
  • <chrono>:
  • Others: <codecvt><new><ratio><system_error><type_traits>.

1.3  C++ Standard Template Libraries (STL) and Headers

STL was developed by Alexander Stepanov and Meng Lee at Hewlett-Packard Lab as proof-of-concept for so-called generic programming. It was released in 1994 and subsequently adopted into the C++98.
STL provides a collection of templates representing containersiteratorsalgorithms and function objects.
  1. container (templatized data structure) can be used to hold fundamental-type values or almost any type of objects, e.g., vector<int>list<string>deque<Person>.
  2. An iterator (a generalization of pointer) is an object that lets you transverse through elements of a container, e.g., vector<int>::iteratorlist<string>::iterator.
  3. Algorithms are used for tasks such as searching, sorting and comparison, e.g., for_eachfindsort.
  4. Function objects are objects that act like functions.
STL is provided in the following headers:
  • <vector>, <list><deque><queue><stack><map><set><bitset><forward_list> (C++11), <unordered_map> (C++11), <unordered_set> (C++11), <array> (C++11): Containers data structures template classes.
  • <iterator>: Iterator for transversing the elements in a container.
  • <algorithm><numeric><functional><utility>: Algorithm and function objects.
  • <initializer_list> (C++11), <memroy> (C++11).

1.4  Boost C++ Libraries

[TODO]

NOTE: I will be updating this post as it has incomplete information(Boost c++ libraries)

Continuation of this post is STL Part 2


I hope it helped!



No comments:

Post a Comment