From 15de20aff540b15a5e74ba058d8c3722d18231b9 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 27 Apr 2021 20:28:11 -0500 Subject: Hacked together something with C++20 C++ is quite a monstrous language indeed!--- channels/channel.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 channels/channel.cpp diff --git a/channels/channel.cpp b/channels/channel.cpp new file mode 100644 index 0000000..8c5b090 --- /dev/null +++ b/channels/channel.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +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(c.read()) << endl; + std::string y = "Hello world"; + c.write(y); + std::cout << std::any_cast(c.read()) << endl; +} -- cgit v1.2.3-70-g09d2