C++ Logo

std-proposals

Advanced search

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

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Mon, 24 Apr 2023 18:02:33 +0300
On Mon, 24 Apr 2023 at 17:59, Ville Voutilainen
<ville.voutilainen_at_[hidden]> wrote:
>
> On Mon, 24 Apr 2023 at 17:52, 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};
>
> namespace longish {
> namespace verbosish {
> namespace tediousish {
> struct X {};
> struct Y {};
> struct Z {};
> }
> }
> }
>
> namespace my_shorten {
> using namespace longish::verbosish::tediousish;
> }
>
> int main() {
> using my_shorten::X;
> using my_shorten::Y;
> using my_shorten::Z;
> X x;
> Y y;
> Z z;
> }

Alternatively

namespace longish {
    namespace verbosish {
        namespace tediousish {
            struct X {};
            struct Y {};
            struct Z {};
        }
    }
}


int main() {
    namespace rly_shrt = longish::verbosish::tediousish;
    using rly_shrt::X;
    using rly_shrt::Y;
    using rly_shrt::Z;
    X x;
    Y y;
    Z z;
}

Received on 2023-04-24 15:02:45