C++ Logo


Advanced search

Re: [std-proposals] New attribute to add implicit using statements for template parameter lists

From: Ryan Klaus <rfklaus117_at_[hidden]>
Date: Tue, 29 Nov 2022 12:12:02 -0600
Still gotta digest most of this, but I just want to quickly clear up some
possible confusions here.

I don't think my proposal is not saying that using N::f would NOT opt in
the namespace N. The opt-in is done only via the attribute-like syntax.

For example:

namespace ABC {

enum class Color

enum class Shape

[[context(using enum Color)]]
template <Color T_color, Shape T_shape>
class Rock { ... };


This would allow for this usage:

auto rock = ABC::Rock<Green, ABC::Shape::Sphere>{};

It would NOT allow for this usage:

auto rock = ABC::Rock<Green, Sphere>{};

Because the shape enum does not have a corresponding using statement.
We could also look at this example:

[[context(using namespace ABC)]]
template <Color T_color, Shape T_shape>
class Rock { ... };

Which would allow for this:

auto rock = ABC::Rock<Color::Green, Shape::Sphere>{};

It's as though there was a "using namespace ABC;" before that line, but
that only affects the parameter list.
Similarly with the previous example, it's as if we had "using enum
ABC::Color;" before that line, but it's scoped specifically to the param
list for ABC::Rock.

So the expression itself is in no way opting itself into a namespace. Some
other statement somewhere else is explicitly opting in to it, just with a
narrower scope. I think that's an important distinction.


Received on 2022-11-29 18:12:15