C++ Logo

SG7

Advanced search

Subject: Re: Metaprogramming
From: Ville Voutilainen (ville.voutilainen_at_[hidden])
Date: 2020-10-27 14:45:56


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.


SG7 list run by sg7-owner@lists.isocpp.org

Older Archives on Google Groups