Date: Sat, 22 Mar 2025 08:42:13 +0100
And free functions which are just as much part of the api as member
functions? What about overload resolutions? I feel this may increase
complexity in compilers without giving any tangible benefits. You save a
few characters but can't really do anything that you can't do now.
My 2 cents anyway.
// Robin
On Sat, Mar 22, 2025, 07:55 Vaibhav Parate via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> Hello,
> Before I spend time on a formal paper for this idea, I want some feedback
> and suggestions.
>
> *Idea:*
> I'd like to propose a *with* block for C++ that allows extending the
> scope of objects, making field access easier and reducing redundant
> qualifiers.
>
> *Motivation (while working on some personal projects):*
> Currently, in C++, working with objects often requires repeatedly
> qualifying fields with *object->* or *object.* inside functions and
> lambdas. This leads to unnecessary verbosity, especially when dealing with
> deeply nested structures.
>
> *Example:*
> *C++ Currently (It is readable but very quickly gets messy, specially when
> you are the author of the entire codebase):*
> void foo (A a, B* b, C& c) { // let's assume A, B, and C are types
>
> a.doSomething();
>
> b->doSomethingElse();
> // some other calles
> c.trySomethingElse();
>
> }
>
> *C++ with "with" blocks:*
> void foo (A a, B* b, C& c) {
>
> with (a, *b, c) {
>
> doSomething();
>
> doSomethingElse();
> // some other calles
> trySomethingElse();
>
> }
>
> }
>
> *Or if you want to use them for the entire function? Consider this:*
> void foo (A a, B* b, C& c) with (a, *b, c) {
>
> doSomething();
> doSomethingElse();
> // some other calles
> trySomethingElse();
>
> }
>
> *What about field name collisions?*
> They can be easily solved using existing syntax of using *object.* or
> *object->*.
>
> *Maybe it will be harder for people to port old code that uses "with" as
> an identifier (variable name etc.) what about that?*
> It's not necessary to use this exact keyword, it can be something else
> like "*using*" which is already a keyword.
>
> *Why?*
> I always find it annoying to use qualifiers while initializing objects,
> yeah there are constructors (and other initializers), but there are
> sometimes where constructors aren't enough and the object needs to be
> initialized in different ways. I may be wrong here and maybe the only one
> facing these issues, but does it hurt to have this feature?
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
functions? What about overload resolutions? I feel this may increase
complexity in compilers without giving any tangible benefits. You save a
few characters but can't really do anything that you can't do now.
My 2 cents anyway.
// Robin
On Sat, Mar 22, 2025, 07:55 Vaibhav Parate via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> Hello,
> Before I spend time on a formal paper for this idea, I want some feedback
> and suggestions.
>
> *Idea:*
> I'd like to propose a *with* block for C++ that allows extending the
> scope of objects, making field access easier and reducing redundant
> qualifiers.
>
> *Motivation (while working on some personal projects):*
> Currently, in C++, working with objects often requires repeatedly
> qualifying fields with *object->* or *object.* inside functions and
> lambdas. This leads to unnecessary verbosity, especially when dealing with
> deeply nested structures.
>
> *Example:*
> *C++ Currently (It is readable but very quickly gets messy, specially when
> you are the author of the entire codebase):*
> void foo (A a, B* b, C& c) { // let's assume A, B, and C are types
>
> a.doSomething();
>
> b->doSomethingElse();
> // some other calles
> c.trySomethingElse();
>
> }
>
> *C++ with "with" blocks:*
> void foo (A a, B* b, C& c) {
>
> with (a, *b, c) {
>
> doSomething();
>
> doSomethingElse();
> // some other calles
> trySomethingElse();
>
> }
>
> }
>
> *Or if you want to use them for the entire function? Consider this:*
> void foo (A a, B* b, C& c) with (a, *b, c) {
>
> doSomething();
> doSomethingElse();
> // some other calles
> trySomethingElse();
>
> }
>
> *What about field name collisions?*
> They can be easily solved using existing syntax of using *object.* or
> *object->*.
>
> *Maybe it will be harder for people to port old code that uses "with" as
> an identifier (variable name etc.) what about that?*
> It's not necessary to use this exact keyword, it can be something else
> like "*using*" which is already a keyword.
>
> *Why?*
> I always find it annoying to use qualifiers while initializing objects,
> yeah there are constructors (and other initializers), but there are
> sometimes where constructors aren't enough and the object needs to be
> initialized in different ways. I may be wrong here and maybe the only one
> facing these issues, but does it hurt to have this feature?
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2025-03-22 07:42:25