Sabtu, 09 Juni 2018

Sponsored Links

Introduction of STL #1: Overview - YouTube
src: i.ytimg.com

Standard Template Library ( STL ) is a software library for C programming languages ​​that affect many sections of the Standard C Library. It provides four components called algorithm , container , function , and iterator .

STL provides a set of common classes for C, such as containers and associative arrays, which can be used with any type of congenital and user-defined types that support some basic operations (such as copying and assigning). The STL algorithm does not depend on the container, which significantly reduces library complexity.

STL achieves results through the use of templates. This approach provides time-compaction polymorphisms that are often more efficient than traditional run-time polymorphisms. The modern C compiler is tuned to minimize penalty abstraction arising from heavy STL usage.

STL is created as the first library of generic algorithms and data structures for C, with four ideas in mind: generic programming, absolute without loss of efficiency, Von Neumann calculation model, and semantic value.


Video Standard Template Library



Composition

Container

STL contains container container and associative container. Containers are objects that store data. Standard sequence containers include vector , deque , and list . The standard associative container is class = "mw-highlight" dir = "ltr"> multiset , map , multimap , hash_set , hash_map , hash_multiset and hash_multimap . There is also container adapter queue , priority_queue , and stack , it is a container with special interface, using another container as an implementation.

Iterators

STL implements five different types of iterators. These are input iterators (which can only be used to read sequence values), output iterators (which can only be used to write sequence values), forward iterators (which can be read, written to, and moved forward), bidirectional iterators (which are like forward iterators, but can also move backwards) and random access iterators s (which can move freely a number of steps in one operation).

It is possible to have a two-way iterator act like a random access iterator, so moving forward ten steps can be done by simply moving forward one step at a time as much as ten times. However, having different random access iterators offers an efficiency advantage. For example, a vector will have random iterator access, but the list is just a two-way iterator.

Iterators are a key feature that enables STL announcements. For example, an algorithm for reversing a sequence can be implemented using a two-way iterator, and then the same implementation can be used on lists, vectors and deques. User-generated containers should only provide an iterator that implements one of the five standard iterator interfaces, and all algorithms provided in the STL can be used in the container.

This generality also comes at a price sometimes. For example, doing a search on an associative container such as a map or set can be slower using the iterator than by calling the member function offered by the container itself. This is because an associative collection method can take advantage of the knowledge of internal structure, which is not clear to algorithms that use iterators.

Algorithm

A large number of algorithms for performing activities such as search and sorting are provided in STL, each implemented to require a certain iterator level (and therefore will work on any container that provides interfaces by the iterator). Search algorithms such as binary_search and lower_bound using binary search and such sorting algorithms require that the data type should apply the comparison operator & lt; or a special comparator function must be specified; Such comparison or comparison comparison operators should insure weak orders. Apart from this, an algorithm is provided to create stacks of various elements, generating lexicographic permutations ordering various elements, combining sorted ranges and unifying, crossing, sorted range differences.

Function

The STL includes classes that overload the function call operator ( operator () ). An example of such a class is called a function or function object. Functors allow the behavior of related functions to be parameterized (eg via arguments passed to the functor constructor) and can be used to keep the per-functor status information linked together with the function. Because functions and function pointers can be invoked using the syntax of the calling function, they are exchanged as arguments for templates when the corresponding parameters only appear in the context of function calls.

A very common type of functor is its predicate. For example, algorithms like find_if take an invalid predicate that operates on circuit elements. Algorithms such as sort, partial_sort, nth_element, and all containers are sorted using binary predictions that should provide a weak sorting, ie should behave like membership tests on transitive, non-reflexive and asymmetric binary relationships. If nothing is provided, these algorithms and containers use less by default, which in turn calls operators less than & lt;.

Maps Standard Template Library



History

The STL architecture is largely the creation of Alexander Stepanov. In 1979 he began to devise the initial idea of ​​generic programming and explore their potential to revolutionize software development. Although David Musser had developed and advocated some aspects of generic programming in 1971, he was limited to a rather specialized software development field (computer algebra).

Stepanov recognized the full potential for generic programming and persuaded his colleagues at General Electric Research and Development (including, especially, David Musser and Deepak Kapur) that generic programming should be pursued as a comprehensive foundation for software development. At that time there was no real support in the programming language for generic programming.

The first major language providing such support is Ada (ANSI standard 1983), with its generic unit feature. In 1985, the Eiffel programming language became the first object-oriented language to include intrinsic support for a generic class, combined with the idea of ​​object-oriented inheritance. In 1987 Stepanov and Musser have developed and published Ada libraries for list processing which is the result of much of their research on generic programming. However, Ada has not achieved much acceptance outside the defense industry and C seems more likely to be widely used and provide good support for generic programming even though the language is relatively immature. Another reason to switch to C, which Stepanov recognized from the beginning, is the C/C computing model that allows very flexible access to storage via pointers, which is very important for general reach without loss of efficiency.

Much research and experimentation is required, not only to develop individual components, but to develop the overall architecture for component libraries based on generic programming. First on AT & amp; T Bell Laboratories and later at Hewlett-Packard Research Labs (HP), Stepanov experimented with many architectural formulations and algorithms, first in C and then in C. Musser collaborated on this research and in 1992 Meng Lee joined the Stepanov project at HP and became a major contributor.

This work will undoubtedly continue for some time only as a research project or will best produce HP's proprietary library, if Andrew Koenig of Bell Labs does not become aware of the work and asks Stepanov to present the main ideas in November 1993 to the ANSI committee meeting/ISO for standardization C. The committee's response was very favorable and led to a request from Koenig for an official proposal in time for a March 1994 meeting. Despite the enormous time pressure, Alex and Meng were able to produce a draft proposal that received preliminary approval at the meeting.

The committee has several requests for changes and extensions (some of which are large), and a small group of committee members meets with Stepanov and Lee to help arrange the details. The requirements for the most significant extension (associative container) should prove consistent with fully implementing it, the assigned Stepanov task to Musser. Stepanov and Lee produced a proposal that received final approval at the ANSI/ISO committee meeting in July 1994. (Additional details from this history can be found at Stevens.) Furthermore, the Stepanov and Lee 17 documents are incorporated into the ANSI/ISO C standard design (1, from clauses 17 to 27). It also affects other parts of the Standard C Library, such as string facilities, and some of the previously adopted standards in the area are revised.

Regardless of STL's success with the committee, there are still questions about how STL will make its way into actual availability and usage. With the STL requirements part of the publicly available design standard, compiler vendors and independent software library vendors can certainly develop their own implementations and market them as separate products or as selling points for other items. One of the first editors, Atul Saini, was one of the first to recognize commercial potential and began exploring it as a business line for his company, Modena Software Incorporated, even before the STL was fully accepted by the committee.

The prospect of deployment of STLs was widely dispersed with Hewlett-Packard's decision to make its implementation available for free on the Internet in August 1994. This implementation, developed by Stepanov, Lee, and Musser during the standardization process, became the basis of many implementations offered by vendors compiler and current library.

C++ Standard Template Library - ppt download
src: slideplayer.com


Criticism

The implementation quality of C compiler

The Quality Implementation (QoI) of C compilers has a major impact on the usefulness of STL (and the templated code in general):

  • Error messages involving templates tend to be very long and difficult to decipher. This issue has been deemed so severe that a number of tools have been written that simplify and update STL related error messages to make them easier to understand.
  • The use of careless templates may cause the code to swell. This has been overcome with special techniques in the application of STL (eg using internal container voids and other "template template" techniques) and improving compiler optimization techniques. However, this symptom is similar to manually copying a set of functions manually to work with different types, as both can be avoided with care and good technique.
  • Template instantiation can increase compilation time and memory usage, in return because it usually reduces runtime decision making (eg via virtual functions). Until compiler technology is sufficiently developed, this problem can only be partially removed by careful coding, avoiding certain idioms, and not using inappropriate templates or where compile-time performance is prioritized.

Other issues

  • The initialization of STL containers with constants in the source code is not as easy as the data structure inherited from C (discussed in C 11 with the initializer list).
  • The STL container is not intended to be used as a base class (its destructor is intentionally non-virtual); coming from the container is a common mistake.
  • The concept of an iterator implemented by STL can be difficult to understand at first: for example, if the value indicated by the iterator is removed, the iterator itself is no longer valid. This is the common source of errors. Most STL implementations provide a slower debug mode, but can find such errors when used. Similar problems exist in other languages, such as Java. Range has been proposed as a safer and more flexible alternative to the iterator.
  • A particular iteration pattern does not map to the STL iterator model. For example, a callback enumeration API can not be performed to match the STL model without using coroutines, which are platform-dependent or unavailable, and are beyond the C standard.
  • Compiler compliance does not guarantee that the Allocator object, which is used for memory management for containers, will work with country-dependent behavior. For example, portable libraries can not determine the type of allocator that will draw memory from a variety of different sources using different allocator objects of that type. (Meyers, p.Ã, 50) (discussed in C 11).
  • An incomplete set of algorithms: for example, the copy_if is abandoned, even though it has been added in C 11.

C++ In Hindi - Standard Template Library (STL) - सी++ हिंदी ...
src: i.ytimg.com


Implementations

  • Original STL Implementation by Stepanov and Lee. 1994, Hewlett-Packard. No longer maintained.
  • SGI STL, based on the original implementation by Stepanov & amp; Lee. 1997, Silicon Graphics. No longer maintained.
  • libstdc by the GNU Project (is part of libg)
  • libc from LLVM
  • STLPort, based on SGI STL
  • Rogue Wave Standard Library (HP, SGI, SunSoft, Siemens-Nixdorf)
  • STL DINUM Library by P.J. Plauger
  • The Microsoft STL sent with Visual C is a licensed derivative of Dinkum's STL.
  • Apache C Standard Library (The starting point for this library is the 2005 version of the Rogue Wave standard library)
  • EASTL, developed by Paul Pedriana in Electronic Arts and published as part of EA Open Source.

C++ Standard Template Library - ppt download
src: slideplayer.com


See also

  • References template C
  • C 11
  • Upgrade C Library

Advanced C++ Training. - ppt download
src: slideplayer.com


Note


Learn STL: Introduction of Templates - YouTube
src: i.ytimg.com


References


Laboratorio Análisis y Diseño de Algoritmos 2 Biblioteca estándar ...
src: images.slideplayer.es


External links

  • Reference C
  • Reference C STL, including feature C 11
  • STL program guide (broken) guide from SGI
  • Apache (formerly Rogue Wave) C Reference Standard Library Class
  • Apache (formerly Rogue Wave) C User's Guide Standard Library
  • Bjarne Stroustrup on The emergence of STL (Page 5, Section 3.1)
  • C Standard Specification

Source of the article : Wikipedia

Comments
0 Comments