C++
CMake
c++ source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
CPP Meta
Clang 18.1.8
Options
Source code
#include <string> #include <concepts> #include <iostream> using namespace std::meta; consteval void property(class_builder& b, type type, std::string name) { auto member_name = identifier{("m_" + name).c_str()}; append_field(b, member_name, type); // getter { method_prototype mp; object_type(mp, make_const(decl_of(b))); return_type(mp, make_lvalue_reference(make_const(type))); append_method(b, identifier{("get_" + name).c_str()}, mp, [member_name](method_builder& b){ append_return(b, make_field_expr( make_deref_expr(make_this_expr(b)), member_name)); }); } // setter { method_prototype mp; append_parameter(mp, "x", make_lvalue_reference(make_const(type))); object_type(mp, decl_of(b)); return_type(mp, ^void); append_method(b, identifier{("set_" + name).c_str()}, mp, [member_name](method_builder& b){ append_expr(b, make_operator_expr( operator_kind::assign, make_field_expr(make_deref_expr(make_this_expr(b)), member_name), make_decl_ref_expr(parameters(decl_of(b))[1]) )); }); } } struct Book { % property(^std::string, "author"); % property(^std::string, "title"); }; int main() { Book b; b.set_title("The Hitchhiker's Guide to the Galaxy"); b.set_author("Douglas Adams"); std::cout << b.get_title() << " by " << b.get_author() << '\n'; }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree