diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-02-02 10:00:29 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-02-02 10:00:29 -0500 |
commit | e97adda9758dab0e12e7e54608dbf9557f0928c7 (patch) | |
tree | 79498ed20025f96a7a3e0ee0880361bf37041ea8 /test.cpp | |
parent | 5882fac07ab1215ec4bbc859c693b28b06e6b469 (diff) |
C++ highlighting, except for raw strings
Diffstat (limited to 'test.cpp')
-rw-r--r-- | test.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..534dfca --- /dev/null +++ b/test.cpp @@ -0,0 +1,55 @@ +#include <iostream> + +using std::cout; + +template<typename T> +class Option { +public: + Option<T>() { + exists = false; + } + Option<T>(T const &t) { + set(t); + } + void set(T const &t) { + exists = true; + x = t; + } + void clear() { + exists = false; + } + T *get() { + if (exists) + return &x; + else + return nullptr; + } + T const *get() const { + if (exists) + return &x; + else + return nullptr; + } +private: + bool exists; + T x; +}; + +template<typename T> +void print_option(Option<T> const &o) { + T const *ptr = o.get(); + if (ptr) + cout << *ptr << "\n"; + else + cout << "None\n"; +} + +int main() { + Option<int> o(7); + print_option(o); + o.clear(); + print_option(o); + o.set(133); + print_option(o); + return 0; +} |