File: std.yo

package info (click to toggle)
c%2B%2B-annotations 12.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,044 kB
  • sloc: cpp: 24,337; makefile: 1,517; ansic: 165; sh: 121; perl: 90
file content (39 lines) | stat: -rw-r--r-- 1,975 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
The tt(std) namespace is reserved by bf(C++). The standard defines many
entities that are part of the runtime available software (e.g., tt(cout, cin,
cerr)); the templates defined in the em(Standard Template Library) (cf.
chapter ref(STL)); and the em(Generic Algorithms) (cf. chapter ref(GENERIC))
are defined in the tt(std) namespace.

Regarding the discussion in the previous section, tt(using)
declarations may be used when referring to entities in the tt(std) namespace.
For example, to use the tt(std::cout)
stream, the code may declare this object as follows:
        verb(    #include <iostream>
    using std::cout;)

Often, however, the identifiers defined in the tt(std) namespace can all
be accepted without much thought. Because of that, one frequently encounters a
tt(using) directive, allowing the programmer to omit a namespace prefix when
referring to any of the entities defined in the namespace specified with the
tt(using) directive. Instead of specifying  tt(using) declarations the
following tt(using) directive is frequently encountered:
construction like
        verb(    #include <iostream>
    using namespace std;)

Should a tt(using) directive, rather than tt(using) declarations be used?
As a i(rule of thumb) one might decide to stick to tt(using) declarations, up
to the point where the list becomes impractically long, at which point a
tt(using) directive could be considered.

    Two hi(using: restrictions) restrictions apply to tt(using) directives and
declarations:
    itemization(
    it() Programmers should not declare or define anything inside the
tt(namespace std). This is em(not) compiler enforced but is imposed upon user
code by the standard;
    it() tt(Using) declarations and directives should not be imposed upon
code written by third parties. In practice this means that tt(using)
directives and declarations should be banned from header files and should only
be used in source files (cf. section ref(NAMESPACEHDR)).
    )