C++ Logo

sg7

Advanced search

[isocpp-sg7] Fwd: P0707

From: Bengt Gustafsson <bengt.gustafsson_at_[hidden]>
Date: Mon, 21 Oct 2024 23:18:43 +0200
Hi all,

I suggested to Herb that P0707 should use the decorator syntax from
Python instead of the inheritance syntax from Python. I think this would
cause less confusion as the semantics seems to be exactly the same as
Python decorators, modulo the consteval part of it of course. This
decorator syntax could then be applied in various places where you may
want to modify something before actually adding it to the program.

Our conversation is below.

Bengt


-------- Forwarded Message --------
Subject: RE: P0707
Date: Sat, 19 Oct 2024 16:10:05 -0700
From: Herb Sutter <herb.sutter_at_[hidden]>
To: 'Bengt Gustafsson' <bengt.gustafsson_at_[hidden]>



Hi Bengt,

The reason I'm currently using class(decorator) is only because that's
what SG7 last recommended.

I like that, and it did cross my mind when we added @. It's similar to
what I use in Cpp2:

                MyClass: @decorator type = { }

I probably should mention it -- I'll add it to rNext of the paper. Thanks!

Herb

P.S.: Would you like to repeat your feedback to the SG7 reflector? I
think it's a great suggestion.

> -----Original Message-----

> From: Bengt Gustafsson <bengt.gustafsson_at_[hidden]>

> Sent: Saturday, October 19, 2024 2:08 PM

> To: Herb Sutter <herb.sutter_at_[hidden]>

> Subject: P0707

>

> Hi Herb,

>

> why not adopt the

>

> @decorator class MyClass {};

>

> syntax from Python?

>

> We just added the @ character and as far as I can see the semantics
is exactly

> the same as the Python counterpart.

>

> This opens up for allowing decorators on functions and in the future
maybe

> other constructs with the same (rather well-known) syntax. Or maybe
even a

> blanket allowance: Wherever you can put ^^ before a contruct you can put

> @function-name instead and let the consteval function adjust the
contents of

> the following entity.

>

> As long as we haven't used @ for something else there should be no
parsing

> issues. I can imagine that someone wants @ to be an identifier
character but I

> haven't seen a proposal for this.

>

> Bengt

>

>

> --

> Bengt Gustafsson

Received on 2024-10-21 21:18:46