File: perfect.cc

package info (click to toggle)
c%2B%2B-annotations 11.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,244 kB
  • sloc: cpp: 21,698; makefile: 1,505; ansic: 165; sh: 121; perl: 90
file content (156 lines) | stat: -rw-r--r-- 2,635 bytes parent folder | download | duplicates (5)
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
145
146
147
148
149
150
151
152
153
154
155
156
#include <iostream>
#include <utility>
#include <functional>

#include <vector>
#include <string>
#include <stack>
#include <thread>

using namespace std;

struct Forwarder
{
    string d_cl;

    Forwarder()
    :
        d_cl("1234567890")
    {}
    template<typename ...Args>
    string substr(Args &&...args)
    {
        return d_cl.substr(std::forward<Args>(args)...);
    }

////    void fwd(size_t (std::string::*ptr)())

////////////////////////////////////////////////////////////////
//    template <typename Ret, typename Member, typename Arg>
//    Ret fwd(Member member, Arg arg)
//
////        decltype (static_cast<Client &>(
////                    *static_cast<Client *>(0)
////                    ))
//
//
////        decltype(s_r)
//
//// Niet met .*       decltype ((d_cl.*member)(arg))
//
//    {
//        return (d_cl.*member)(arg);
//    }
////////////////////////////////////////////////////////////////

//    template <typename Ret, typename Member, typename ...Args>
//    Ret fwd(Member member, Args&&...args)
//    {
//        return (d_cl.*member)(std::forward<Args>(args)...);
//    }
};


struct X
{
    template <typename T>//, typename ...Args>
    struct result
    {
        typedef void type;
    };

    void operator()(int x)
    {
        cout << "int\n";
    }
    void operator()(double x)
    {
        cout << "double\n";
    }
    void operator()(double x, char const *)
    {
        cout << "double, string\n";
    }
    void operator()(ostream &out, double &x, char const *)
    {
        cout << "double, string\n";
    }
};

struct One
{
    One()
    {
        cout << "One()\n";
    }
    One(int)
    {
        cout << "One(int)\n";
    }
};

struct Two
{
    Two()
    {
        cout << "Two()\n";
    }
    Two(int)
    {
        cout << "Two(int)\n";
    }
};

template <typename Class, typename ...Args>
Class factory(Args &&...args)
{
    return Class(std::forward<Args>(args)...);
}

void calledFunction(ostream &out)
{
    out << "hello\n";
}

void calledFunction(int x)
{
    ++x;
}

void calledFunction(int &x)
{
    ++x;
}

template <typename ...Args>
void caller(Args &&...args)
{
    calledFunction(std::forward<Args>(args) ...);
}

int main()
{
    int x = 0;
    caller(cout);
    caller(x);
    cout << x << '\n';

//    int arg;
//    X x;
//    Forwarder forwarder;
//
//    string &&out = forwarder.substr(5, 2);
//
//    factory<One>();
//    Two two(factory<Two>(3));
//
//    factory<Two>(two);
//
//    cout << out << '\n';

//    forwarder.function(x, 0);
//    forwarder.function(x, 0.0);
//
//    double d;
//    thread t(x, ref(cout), ref(d), "hi");
}