diff options
author | Anthony Wang | 2021-04-27 20:28:11 -0500 |
---|---|---|
committer | GitHub | 2021-04-27 20:28:11 -0500 |
commit | 15de20aff540b15a5e74ba058d8c3722d18231b9 (patch) | |
tree | 5a26fd88993d5d3bb35b719aa7b3b051adf18727 | |
parent | 914612af3a1a1256478afdf4ccc0e369dd95548d (diff) |
Hacked together something with C++20
C++ is quite a monstrous language indeed!
-rw-r--r-- | channels/channel.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
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 <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; +} |