C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Grouped-namespace "using" statements (floating the idea)

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Tue, 25 Apr 2023 23:44:16 -0400
On Tue, Apr 25, 2023 at 10:34 PM Barry Revzin via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
>
>
> On Mon, Apr 24, 2023, 9:52 AM John Filleau via Std-Proposals <std-proposals_at_[hidden]> wrote:
>>
>> Floating the idea for Grouped-namespace "using" statements.
>>
>> A grouped-namespace using statement is a shorter way to write multiple using statements that share a parent namespace.
>>
>> using a::b::c::X, a::b::c::Y, a::b::c::Z;
>>
>> can be replaced with
>>
>> using a::b::c::{X, Y, Z};
>>
>> PROBLEM
>>
>> Sometimes I have long namespace names, and I want to alias things from that namespace. The current way to do that requires me to retype the namespace a lot. See above.
>>
>> This is annoying at time-of-writing because of the repetition and opportunity for typos. This is annoying at time-of-maintenance when namespace names change.
>>
>> SOLUTION
>>
>> Allow grouped-namespace using statements as seen above.
>>
>> BENEFIT
>>
>> 100% ergonomics.
>>
>> This solves no interesting computer science problems, nor does it introduce world peace.
>>
>> DOWNSIDES
>>
>> I have 0 understanding of the edge cases around this. I just know I want it. If other people want it, we should make it part of the standard.
>>
>> COST
>>
>> One more thing that implementations have to handle.
>
>
> I like this idea. Saves on repeating the namespace, which has very little benefit at that point. Plus it's common for people to just avoid using namespace in preference to using declarations, which are quite verbose today due to the namespace repetition.
>
> Even if the namespace is short, like:
>
> using std::cout, std::endl;
>
> This kind of stuff adds up fast, and
>
> using std::{cout, endl};
>
> is just clearer.
>
> You can't have a { after :: today, so there's no ambiguity. This does make parsing a using declaration more complicated, since it's no longer just a sequence of qualiifed-ids, but it's probably not exceedingly difficult.

I don't much like the use of curly braces around these things, since
those are either introducing a scope or initializing an object. Is it
just as syntactically valid to use `()` or `[]` in those cases?

Received on 2023-04-26 03:44:29