C++ Logo

sg20

Advanced search

Re: [isocpp-ext] namespace composition

From: Bjarne Stroustrup <bjarne_at_[hidden]>
Date: Sat, 29 Apr 2023 15:23:27 -0400
Thanks. Neat, but I don't think the students would appreciate it.


On 4/29/2023 6:26 AM, Matthias Kretz wrote:
> On Saturday, 29 April 2023 03:46:10 CEST Bjarne Stroustrup via Ext wrote:
>> On 4/28/2023 8:55 PM, Ville Voutilainen wrote:
>>> On Sat, 29 Apr 2023 at 03:40, Bjarne Stroustrup <bjarne_at_[hidden]>
> wrote:
>>>>> Name lookup in C++ is complicated. :P
>>>> Too complicated, and there is probably little we can do about it.
>>> Right, but we would curse the language if it just allowed what you're
>>> trying to do, when programming at scale(*). You have
>>> an altruistic hack here, but it's still a hack.
>> Agreed. What we need is a way of getting a portable guarantee that range
>> checking is done for at least non-sneaky uses. This fits with "profiles".
> Yes, I believe we need to cater to users that want bounds checking *and*
> those that don't.
>
> As for another variation of the workaround:
>
> import std;
>
> namespace PPP
> {
> using namespace std;
>
> struct vector {
> void found_our_own() {}
> };
>
> int main(int argc, char** argv);
> }
>
> int main(int argc, char** argv) { return PPP::main(argc, argv); }
>
> // students will then have to work in the PPP namespace:
>
> namespace PPP
> {
> int main(int argc, char** argv) {
> vector v;
> v.found_our_own();
> }
> }
>
>
> Name lookup finds PPP::vector and looks no further.
>
> -Matthias
>

Received on 2023-04-29 19:23:30