diff options
author | RabsRincon <rubrinbla@gmail.com> | 2017-12-09 11:19:45 +0100 |
---|---|---|
committer | RabsRincon <rubrinbla@gmail.com> | 2017-12-09 11:19:45 +0100 |
commit | 43279a61ca8607f66cb10060aaee671d098d68bf (patch) | |
tree | 18c0f93a51902a8b85f0247e4463eba725b4b244 /examples/cppx/default.cpp | |
parent | 030cffffffd2cf1487f9282719c3f38edaa19f62 (diff) | |
download | compiler-explorer-43279a61ca8607f66cb10060aaee671d098d68bf.tar.gz compiler-explorer-43279a61ca8607f66cb10060aaee671d098d68bf.zip |
Fix various points raised after code reviews
Some fixes, a great slam and then some
Diffstat (limited to 'examples/cppx/default.cpp')
-rw-r--r-- | examples/cppx/default.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/examples/cppx/default.cpp b/examples/cppx/default.cpp new file mode 100644 index 000000000..503cffe41 --- /dev/null +++ b/examples/cppx/default.cpp @@ -0,0 +1,47 @@ +//==================================================================== +// Library code: implementing the metaclass (once) + +$class basic_value { + basic_value() = default; + basic_value(const basic_value& that) = default; + basic_value(basic_value&& that) = default; + basic_value& operator=(const basic_value& that) = default; + basic_value& operator=(basic_value&& that) = default; + + constexpr { + for... (auto f : $basic_value.variables()) + if (!f.has_access()) f.make_private(); + for... (auto f : $basic_value.functions()) { + if (!f.has_access()) f.make_public(); + compiler.require(!f.is_protected(), "a value type may not have a protected function"); + compiler.require(!f.is_virtual(), "a value type may not have a virtual function"); + compiler.require(!f.is_destructor() || f.is_public(), "a value destructor must be public"); + } + } +}; + +$class value : basic_value { }; + + +//==================================================================== +// User code: using the metaclass to write a type (many times) + +value Point { + int x = 0, y = 0; + Point(int xx, int yy) : x{xx}, y{yy} { } +}; + +Point get_some_point() { return {1,1}; } + +int main() { + + Point p1(50,100), p2; + p2 = get_some_point(); + p2.x = 42; + +} + +// Compiler Explorer note: Click the "triangle ! icon" to see the output: +constexpr { + compiler.debug($Point); +} |