C++ Logo

sg7

Advanced search

Re: [SG7] Metaprogramming

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Tue, 27 Oct 2020 21:45:56 +0200
On Tue, 27 Oct 2020 at 21:38, David Rector via SG7 <sg7_at_[hidden]> wrote:
> // PROPOSED ALTERNATIVE: i.e. same "semantics" (= generated AST nodes etc)
> // after parsing, just different "syntax" (= Parser implem):
>
> template<typename T>
> consteval void inject_property(string_view id) {
> string member_name = "m_" + id;
> string getter_name = "get_" + id;
> string setter_name = "set_" + id;
>
> meta << "private:"
> " T " << member_name << ";"
> "public: "
> " T const& " << getter_name << "() const {"
> " return " << member_name << ";"
> " }"
> " void " << setter_name << "(T const& x) {"
> << member_name << " = x;"
> " }";
> }

That still looks nothing like a class definition.

> In particular, regarding familiarity: the output stream syntax proposed above is how people metaprogram nowadays

That's not metaprogramming, it's writing data into files. And I'd bet
that would look rather different if we
had a standardized format() like we will in C++20, as opposed to
having ostream as your only tool.
Because with format, I could make generated class definitions look
more like class definitions in the code that
generates them, without having all that <<-noise in it.

Received on 2020-10-27 14:46:10