C++ Logo


Advanced search

[std-proposals] Allowing `using namespace` in class definition

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Mon, 13 Mar 2023 15:00:13 +0300

I'm wondering why `using namespace` directives are not allowed within
class definitions? It would seem not fundamentally different from other
contexts, like within a function body.

The use case I have in mind is related to user-defined literals:

  struct foo
    using namespace std::literals;

    std::string str;

    foo() : str("abcd"sv) {} // using-directive needed for this

PS: Yes, I know I could move the constructor definition to namespace
scope and use the using directive there. I don't want to, because I want
this constructor to be inline, in the header, and yet I don't want to
have using directives in a public header at the namespace scope.

Received on 2023-03-13 12:00:39