C++ Logo

sg7

Advanced search

Re: [SG7] Metaprogramming

From: Peter Dimov <pdimov_at_[hidden]>
Date: Sat, 24 Oct 2020 20:32:23 +0300
David Rector wrote:

> This probably is too big a can of worms to open but FWIW I favor an object
> oriented hierarchy, rather than `meta::info`. I.e. `reflexpr(somefunc)`
> should return a `meta::FunctionDecl` object, which is also a
> `meta::NamedDecl` etc. We are writing C++, not C, and an object oriented
> reflection hierarchy would be more user-friendly.

(Sorry for not replying to the right message -- I wasn't subscribed then
yet.)

This has its own problems. In the current framework, all "methods" work on
meta::info, so you can write a function that takes std::vector<meta::info>
that contains FunctionDecls and do some FunctionDecl-y things on them. This
is still "type safe" because errors (passing reflexpr(void)) are detected at
compile time.

If object-oriented, you have to write this to take vector<FunctionDecl>. But
then consider code that takes all the static member functions of a given
class X. In the meta::info world, this just returns vector<meta::info> and
you can pass it to your function. In the object oriented world, what will it
return? A vector<MemberDecl>? That's not a vector<FunctionDecl>, so you
can't call your function with it.

Received on 2020-10-24 12:32:38