blob: f1964db1e004270812edf277f9b2537f3fd9b942 (
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()) << std::endl;
std::string y = "Hello world";
c.write(y);
std::cout << std::any_cast<std::string>(c.read()) << std::endl;
}
|