blob: 8c5b090769504ab89198732497b495dfcd3a2b1a (
plain)
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
|
#include <iostream>
#include <string>
#include <any>
class channel {
private:
std::any val;
public:
void write(auto v) {
val = v;
}
auto read() {
while (!val.has_value());
auto ret = val;
val.reset();
return ret;
}
};
int main() {
channel c;
int x = 1;
c.write(x);
std::cout << std::any_cast<int>(c.read()) << endl;
std::string y = "Hello world";
c.write(y);
std::cout << std::any_cast<std::string>(c.read()) << endl;
}
|