File: directive.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 (46 lines) | stat: -rw-r--r-- 1,969 bytes parent folder | download | duplicates (2)
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
40
41
42
43
44
45
46
A generalized alternative to the tt(using) declaration is the
emi(using directive):
        verb(    using namespace CppAnnotations;)

Following this directive, em(all) entities defined in the
tt(CppAnnotations) namespace are used as if they were declared by tt(using)
declarations.

    While the tt(using) directive is a quick way to
 hi(namespace: import all names) import all the names of a namespace (assuming
the namespace has previously been declared or defined), it is at the same time
a somewhat dirty way to do so, as it is less clear what entity is actually
used in a particular block of code.

    If, e.g., tt(cos) is defined in the tt(CppAnnotations) namespace,
tt(CppAnnotations::cos) is going to be used when tt(cos) is called. However,
if tt(cos) is em(not) defined in the tt(CppAnnotations) namespace, the
standard tt(cos) function will be used. The tt(using) directive does not
document as clearly as the tt(using) declaration what entity will actually be
used. Therefore use caution when applying the tt(using) directive.

Namespace declarations are context sensitive: when a tt(using namespace)
declaration is specified inside a compound statement then the declaration is
valid until the compound statement's closing curly bracket has been
encountered. In the next example a string tt(first) is defined without
explicit specifying tt(std::string), but once the compound statement has ended
the scope of the tt(using namespace std) declaration has also ended, and so
tt(std::) is required once again when defining tt(second):
        verb(    #include <string>
    int main()
    {
        {
            using namespace std;
            string first;
        }
        std::string second;
    })

A tt(using namespace) directive cannot be used within the
declaration block of a class- or enumeration-type. E.g., the following example
won't compile:
        verb(    struct Namespace
    {
        using namespace std;      // won't compile
    };)