"Effective C + +": Clause 52-Clause 55

Source: Internet
Author: User
Tags traits

The last of these three clauses belongs to miscellaneous. Clause 53 tells us not to ignore the warning, although the program can be compiled through, but to understand the warning message. Clause 54 and Article 55 explain C + + libraries, one is the TR1 document, and the other is boost. The C++11 standard is now set and has compiler support. Some of the Boost library content has been standardized to c++11, and instead of learning boost, familiarize yourself with the Boost library content in c++11.

    • Article 53 do not neglect the compiler's warnings
    • Article 54 familiarize yourself with the standard library of programs, including TR1
    • Article 55 familiarize yourself with boost

Article 53: Don't overlook compiler warnings

Many programmers routinely ignore compiler warnings. Perhaps they think that if the problem is serious, then the compiler should give an error instead of a warning. This idea is very harmful in C + +, as illustrated by an example:

  class B{    public:        virtualvoidfconst;    };    public B{    public:        virtualvoidf();    };

Here you want D::f to redefine the virtual function b::f, but the D is not declared as Const. The compiler does not make an error and may give the following warning

warning: D::f() hides virtual B::f()

You might think that d::f () hides the b::f, which is exactly what we want to do. But the compiler is trying to tell you that B::f is not re-declared in D, but is obscured. If you ignore this warning, such as causing error behavior.

Learn from compiler warnings that learning about warning messages is not the same as what they seem to mean. Programs that do not have any warnings at the highest warning level are ideal, but have a deep understanding of warning, and you can choose to ignore certain warning messages. But remember, before ignoring this warning, be sure to understand its true intentions.

Warning messages are related to the compiler, and different compilers have different warning standards. For example, the function in the above code obscures the compiler in another compiler, and there may be no warning.

Summarize

    • Take a warning message from the compiler seriously. Try to do nothing without warning at your compiler's highest warning level.
    • Do not rely too much on the compiler's alarm capabilities, because different compilers treat things differently. A warning code, ported to another compiler, may not have any warnings.
Article 54: Familiarize yourself with the standard library of programs including TR1

The C + + specification in this book was developed in 1998. Now c++11, that c++0x has been developed, and c++14 in the discussion. The discussion of this article is about the boost library, when there is no new standard, some new language features to the technical reporting content program to everyone, TR1 representative Technical Report 1.

Now take a look at what the standard libraries of c++98 Garu are:

    • STL, Standard Template Library.
    • IOStreams, which contains user-defined buffering capabilities, internationalized I/O, and first-defined objects cin, cout, Cerr, and clog.
    • National support, including multi-regional capacity.
    • Numeric processing, including complex template (complex) and pure numeric values (Valarray).
    • Abnormal hierarchy System (exception hierarchy).
    • C89 Standard Program Library.

TR1 details 14 new components (component, the program unit), placed within the namespace Std::tr1. Here's an example of a TR1 component:

    • Smart pointers
    • Tr1::function, which can represent any callable entity (callable, that is, any function or function object), as long as the signature compound target.
    • Tr1::bind, it can do everything that the STL binder (Binders) bind1st and bind2nd do, and more.

The TR1 components are divided into 2 groups, and the first group provides functions that are unrelated to each other:

    • Hash table, can be used to implement set, map and so on.
    • Regular Expressions (Regular expression), including string lookups and substitutions based on regular expressions.
    • Tuples (variable group), which is a new generation of pair template in the standard program library.
    • Tr1::array, the essence is an array that supports member functions begin and end.
    • TR1::MEM_FN, this is a statement construct that is consistent with the member function pointer (member function pointer).
    • Tr1::reference_wrapper, a facility that makes reference behave more like an object.
    • The random number generation tool, which goes far beyond Rand.
    • Mathematical special functions.
    • C99 compatible extensions.

The second set of TR1 components consists of more sophisticated template programming techniques

    • Type traits, a set of traits classes (* * clause **47) to provide compile-time information for the type.
    • Tr1::result_of, which is a template used to derive the return type of a function call.

Summarize

    • The main functions of the standard program of C + + are composed of STL, iostream and locales. and contains the C99 standard library.
    • TR1 adds support for smart pointers, generalized function pointers, hash-based containers, regular expressions, and 10 additional components.
    • TR1 is just a specification that requires a physical, such as boost, to gain the benefits TR1 provides.
Article 55: Get familiar with boost

Boost Library is a high-quality, source-code development, platform-Independent, compiler-independent library. Boost is a community of C + + developers, with a URL of http://boost.org.

Boost has no effect in other C + + organizations. 1. Boost has been created by the C + + Standards Committee with the goal of being a test farm that can be added to the various functions of standard C + +. 2. It accepts the process of procedure and is based on public peer review.

The following is a description of the Boost program library

    • string and Text Processing
    • Container
    • function objects and advanced programming
    • Generic programming
    • Template programming
    • Math and numerical values
    • Correctness and testing
    • Data
    • Inter-language support
    • Memory Miscellaneous

Summarize

    • Boost is a community and a Web site. Dedicated to free, source development, peer review of C + + library development. Boost plays an influential role in the C + + standardization process.
    • Boost offers many TR1 component implementations, as well as many other library applications.

"Effective C + +": Clause 52-Clause 55

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.