STL for C++ Programmers

Author: Leen Ammeraal
Publisher: John Wiley
Price: $49.99
ISBN: 0-471-97181-2
Reviewer: Bob Adkins
Good news—STL, Standard Template Library, is alive and well on Linux. Leen Ammeraal demonstrates this as well as his considerable skills as a master teacher in STL for C++ Programmers. Although the primary focus is not Linux, his many excellent examples are easily adapted to the g++ environment in Linux 2.0++ (his examples adapted for Linux can be found at http://www.cwareco.com/download.html. Ammeraal writes concise yet thorough explanations on each aspect of using STL.
STL started in the 1970s with Alexander Stepanov's ideas about designing general algorithms. Stepanov, together with Meng Lee, took these ideas to HP and developed the first C++ based STL. By 1994, STL was accepted into the C++ draft standard by the ANSI/ISO C++ standards committee.
STL distinguishes general algorithms from the more specialized data and methods encapsulated by ordinary abstract data types. In this way, complex and powerful algorithms can be implemented independently of the data to which they are applied, allowing for generalization and reuse of these algorithms. In STL more familiar object abstraction is reserved for data and methods. These are then tailored and bound to the characteristics of their underlying container type such as sequence containers and associative containers. Examples of this distinction with respect to sequence containers, such as vector objects, are begin, end and insert. These methods access and manipulate the underlying data of the vector container class. However, these methods are specific to the treatment of the data and should not be confused with more general algorithms such as find, sort and other advanced numeric algorithms (e.g., accumulate or inner product). General algorithms are a kind of method abstraction in contrast to more traditional data abstraction.
STL support has been available on Linux since GNU's libg++ 2.6.2. Now with release 2.7.2.1, the library is quite usable for most major features with the exception of name space scoping. There are minor differences with other implementations, such as Borland's BC5 environment, but these differences mostly concern header naming conventions. There is also a curious problem with fstream which involves an unexpected file access mode default.
g++ 2.8.0 will offer a more complete STL based on newer code from SGI and a complete redesign of the compiler's template implementation. Unfortunately, g++ 2.8.0 is not expected to fix the problems with using name spaces.
From the beginning Leen Ammeraal presents a quick and practical startup for the STL beginner. He then explains how to use the sequence containers (vectors, lists and deques), the associative containers (sets and maps) and, later, examines containers derived from these basic types such as stacks, queues and priority queues. As a simple application, he shows how to to build a telephone directory using associative map containers. Later, he demonstrates a more complex map application, called a concordance, which produces a line-oriented index of all words in a text file. He also shows function objects which can be used to build custom ordering relationships among the elements of a container. He moves on to algorithms and the practical details of STL's generic algorithms for manipulating sequences and for sorting. He demonstrates the built-in numeric algorithms which make STL attractive for implementing statistical analysis such as the Least Squares Method.
As his final chapter, Ammeraal presents a wonderfully fun example of “Very Large Numbers”. Here Ammeraal uses STL to calculate pi to an arbitrarily large number of digits. Ammeraal exploits the power of STL to reduce the implementation complexities of defining and operating on extremely large numbers. He notes that, thanks to the STL's vector container, this version is “simpler and more elegant” than an earlier solution he presented in his book Algorithms and Data Structures in C++.
For added spice, I modified his program to generate a histogram of the digits computed for pi. At 100,000 places, digit “1” is a very slight favorite. Moreover, with this example Linux shows its strength. After turning on full g++ optimization, I was able to calculate these 100,000 digits in just under 20 minutes. Under DOS/Windows, Ammeraal indicated that this same calculation took several hours using BC5.

Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




1 hour 18 min ago
8 hours 12 min ago
8 hours 28 min ago
10 hours 20 min ago
16 hours 11 min ago
20 hours 43 min ago
20 hours 44 min ago
22 hours 44 min ago
1 day 7 hours ago
1 day 8 hours ago