C++ Logo

std-proposals

Advanced search

Re: Automatic export literals operators into global scope when the header is included

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Thu, 11 Mar 2021 11:13:59 -0500
On Thu, Mar 11, 2021 at 3:14 AM kang hewill via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
>
> Dear Experts:
>
> When C++14 introduces literals operators, we can conveniently use auto s = "hello"s; to define an std::string, but before that, we must type using std::string_literals::operator""s;.
> This is very unfriendly for users who just want to save typing but often need to define a simple std::string on different files (or for AAA-style enthusiasts). It would be great if these literals operators can be automatically introduced into the global scope when their corresponding headers are included.

No, this would be pretty bad. Literals, once in the global namespace,
cannot later be *removed* from the global namespace. You should not
pollute the global namespace unbidden. Such defines also propagate
through headers to the eventual receiver.

If `using std::string_literals;` is too much for a user to type, then
that's a problem with that user.

Received on 2021-03-11 10:14:14