C++ Logo


Advanced search

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

From: Barry Revzin <barry.revzin_at_[hidden]>
Date: Tue, 25 Apr 2023 21:34:23 -0500
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};
> 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.
> Allow grouped-namespace using statements as seen above.
> 100% ergonomics.
> This solves no interesting computer science problems, nor does it
> introduce world peace.
> 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.
> 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.



Received on 2023-04-26 02:34:35