1. Trang chủ
  2. » Công Nghệ Thông Tin

Standard template library

117 573 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 117
Dung lượng 492,5 KB

Nội dung

Tài liệu này dành cho sinh viên, giáo viên khối ngành công nghệ thông tin tham khảo và có những bài học bổ ích hơn, bổ trợ cho việc tìm kiếm tài liệu, giáo án, giáo trình, bài giảng các môn học khối ngành công nghệ thông tin

Chương Standard Template Library The Standard Template Library • • • • • • Origins of STL Generic programming STL components STL installation STL header files STL incompatibilities The Standard Template Library • The Standard Template Library (STL) is a general-purpose library of container classes (such as vectors, lists, sets and maps) and generic algorithms (such as searching, sorting and merging) • The chief difference between STL and other C++ libraries is that STL containers and algorithms can be "plugged" together in a myriad of different useful ways Problems with libraries • Writing your own library of container classes can be very frustrating because, even if you are familiar with the best techniques, there is rarely time to implement them • Buying a commercial library also has its drawbacks: – Incompatibility – Inefficiency – Unwieldy interfaces Origins of STL • In view of these problems, the ANSI committee for C++ standardisation sought a standard set of container classes • Alexander Stepanov and Meng Lee of Hewlett Packard Laboratories proposed STL, and in 1994 it was accepted as part of the C++ Standard Library Why STL? • STL was chosen as the ANSI standard for several reasons: – Efficiency – Iterators – Generic algorithms – Function objects – Allocators Generic programming • Research into generic programming has aimed to produce libraries of generic, or reusable, software components Generic programming • Each iterator defines the operations that are needed to access the contents of a particular type of container • Class templates are used to define containers and iterators, and function templates are used to define generic algorithms Generic programming • Not every generic algorithm and iterator can be plugged together STL prohibits some combinations because certain algorithms are only efficient when they are used with certain types of containers STL components • Containers • Generic algorithms • Iterators • Adaptors • Function objects • Allocators 10 STL Internet and Web Resources • Tutorials – www.cs.brown.edu/people/jak/programm ing/stl-tutorial/tutorial.html • STL tutorial organized by examples, philosophy, components and extending the STL – www.yrl.co.uk/phil/stl/stl.htmlx • Function templates, class templates, STL components, containers, iterators, adaptors and function objects – www.xraylith.wisc.edu/~khan/software /stl/os_examples/examples.html • Introduction to STL and ObjectSpace STL Tool Kit 10 STL Internet and Web Resources (tt) • References – www.sgi.com/tech/stl • Silicon Graphics STL Programmer’s Guide – Latest information, design documentation and links – www.cppreference.com/cpp_stl.html • Lists constructors, operators and functions for each container • Articles, Books and Interviews – www.byte.com/art/9510/sec12/art3.htm • Provides information on the use of STL – www.sgi.com/tech/stl/drdobbs-interview.h tml • Interview with Alexander Stepanov, one of the STL creators 10 STL Internet and Web Resources (tt) • References – www.sgi.com/tech/stl • Silicon Graphics STL Programmer’s Guide – Latest information, design documentation and links – www.cppreference.com/cpp_stl.html • Lists constructors, operators and functions for each container • Articles, Books and Interviews – www.byte.com/art/9510/sec12/art3.htm • Provides information on the use of STL – www.sgi.com/tech/stl/drdobbs-interview html • Interview with Alexander Stepanov, one of the STL creators 10 #include #include using namespace std; int main() { vector nums1; nums1.insert(nums1.begin(), -999); nums1.insert(nums1.begin(), 14); Câu vector nums2 = nums1; nums2.insert(nums2.begin(), 32); vector nums3; nums3 = nums2; for (i=0; i

Ngày đăng: 23/10/2014, 21:05

TỪ KHÓA LIÊN QUAN