File: main.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (144 lines) | stat: -rw-r--r-- 2,824 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <cstdarg>
#include <cstdlib>
#include "ns.h"

namespace {
    typedef unsigned int my_uint_t;
    int i; // Find the line number for anonymous namespace variable i.

    int myanonfunc (int a)
    {
        return a + a;
    }

    int
    variadic_sum (int arg_count...)
    {
        int sum = 0;
        std::va_list args;
        va_start(args, arg_count);

        for (int i = 0; i < arg_count; i++)
            sum += va_arg(args, int);

        va_end(args);
        return sum;
    }
}

namespace A {
    typedef unsigned int uint_t;
    namespace B {
        typedef unsigned int uint_t;
        int j; // Find the line number for named namespace variable j.
        int myfunc (int a);
        int myfunc2(int a)
        {
             return a + 2;
        }
        float myfunc (float f)
        {
            return f - 2.0;
        }
    }
}

namespace Y
{
    typedef unsigned int uint_t;
    using A::B::j;
    int foo;
}

using A::B::j;          // using declaration

namespace Foo = A::B;   // namespace alias

using Foo::myfunc;      // using declaration

using namespace Foo;    // using directive

namespace A {
    namespace B {
        using namespace Y;
        int k;
    }
}

namespace ns1 {
    int value = 100;
}

namespace ns2 {
    int value = 200;
}

void test_namespace_scopes() {
    do {
        using namespace ns1;
        printf("ns1::value = %d\n", value); // Evaluate ns1::value
    } while(0);
    
    do {
        using namespace ns2;
        printf("ns2::value = %d\n", value); // Evaluate ns2::value
    } while(0);
}

int Foo::myfunc(int a)
{
    test_namespace_scopes();    

    ::my_uint_t anon_uint = 0;
    A::uint_t a_uint = 1;
    B::uint_t b_uint = 2;
    Y::uint_t y_uint = 3;
    i = 3;
    j = 4;
    printf("::i=%d\n", ::i);
    printf("A::B::j=%d\n", A::B::j);
    printf("variadic_sum=%d\n", variadic_sum(3, 1, 2, 3));
    myanonfunc(3);
    return myfunc2(3) + j + i + a + 2 + anon_uint + a_uint + b_uint + y_uint; // Set break point at this line.
}

namespace B {
struct Bar {
    int x() { return 42; }
};
Bar bar;
} // namespace B

namespace A::B {
struct Bar {
    int y() { return 137; }
};
} // namespace A::B

namespace NS1::NS2 {
struct Foo {
    int bar() { return -2; }
};
} // namespace NS1::NS2

namespace NS2 {
struct Foo {
    int bar() { return -3; }
};
} // namespace NS2

int
main (int argc, char const *argv[])
{
    test_lookup_at_global_scope();
    test_lookup_at_file_scope();
    A::test_lookup_at_ns_scope();
    A::B::test_lookup_at_nested_ns_scope();
    A::B::test_lookup_at_nested_ns_scope_after_using();
    test_lookup_before_using_directive();
    test_lookup_after_using_directive();
    ::B::Bar bb;
    A::B::Bar ab;
    return Foo::myfunc(12) + bb.x() + ab.y() + NS1::NS2::Foo{}.bar() +
           NS2::Foo{}.bar();
}