Library Additions

C++11 adds several specialized libraries. An extensible random number library, supported by the random header file, provides much more extensive and sophisticated random number facilities than rand(). For example, it offers a choice of random-number generators and a choice of distributions, including uniform (like rand()), binomial, normal, and several others.

The chrono header file supports ways to deal with time duration.

The tuple header file supports the tuple template. A tuple object is a generalization of a pair object. Whereas a pair object can hold two values whose types need not be the same, a tuple can hold an arbitrary number of items of different types.

The compile-time rational arithmetic library, supported by the ratio header file, allows the exact representation of any rational number whose numerator and denominator can be represented by the widest integer type. It also provides arithmetic operations for these numbers.

One of the most interesting additions is a regular expression library, supported by the regex header file. A regular expression specifies a pattern that can be used to match contents in a text string. For example, a bracket expression matches any single character in the brackets. Thus, [cCkK] matches a single c, C, k, or K, and [cCkK]at matches the words cat, Cat, kat, and Kat. Other patterns include d for a digit, w for a word, for a tab, and many, many others. The fact that a backslash has a special meaning in C++ as the first character in an escape sequence requires a pattern like d wd (that is, digit-tab-word-digit) to be written as the string literal "\d\t\w\d", using \ to represent . This is one reason the raw string was introduced (see Chapter 4); it enables you to write the same pattern as R"d w ".

Unix utilities such as ed, grep, and awk used regular expressions, and the interpreted language Perl extended their capabilities. The C++ regular expressions library allows you to choose from several flavors of regular expressions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.151.220