Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #70652

Re: I'd like to have unusing

From "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.lang.c++
Subject Re: I'd like to have unusing
Date 2019-12-25 22:56 +0100
Organization A noiseless patient Spider
Message-ID <qu0lu3$n91$1@dont-email.me> (permalink)
References <qst9g8$2d7$1@news.albasani.net> <qstd3m$dn$1@dont-email.me> <TKNMF.109730$%d1.102464@fx45.iad> <qu0c5p$3qk$1@dont-email.me> <yEQMF.111195$%d1.9038@fx45.iad>

Show all headers | View raw


On 25.12.2019 22:37, Pavel wrote:
> Alf P. Steinbach wrote:
>> On 25.12.2019 19:19, Pavel wrote:
>>> Alf P. Steinbach wrote:
>>>> On 12.12.2019 12:49, Bonita Montero wrote:
>>>>> In a header I'm fixed to write the std::-prefixes since I can't use
>>>>> "using namespacee std" because this would be against the exepectations
>>>>> of those including the header.
>>>>> So I had a simple idea: with every "using namespace xxx" an counter for
>>>>> the namespace xxx would be incremented and at the end of block where
>>>>> the
>>>>> prefixes where used implicitly there would be a new "unusing"-directive
>>>>> that derements the counter and when it becomes zero, the implicit
>>>>> attachment to symbols is disabled.
>>>>
>>>>
>>>> A workaround until you get that feature proposed and adopted, is to use
>>>> a clean /exporting namespace/.
>>>>
>>>> For example, you may want the stuff to be available in namespace
>>>> `bonitas`.
>>>>
>>>> Then do like this, first defining stuff in the /defining/ namespace
>>>> `bonitas::_`, or whatever, really, just not same as exporting ns:
>>>>
>>>>       // Here a stern admonition to not use namespace bonitas::_.
>>>>       // Then:
>>>>       namespace bonitas::_ {
>>>>           using namespace std; // Oh joy
>>>>           void stuff() { feclearexcept(FE_ALL_EXCEPT); }
>>>>       }
>>>>
>>>>       namespace bonitas {
>>>>           using _::stuff;
>>>>       }
>>>>
>>>> Regarding `_` a main difference from the usual `impl` or `detail`
>>>> namespace (e.g. Boost's `detail`) is that `_` here contains stuff meant
>>>> to be used directly by client code, not just implementation details.
>>> I personally don't see anything wrong in defining few things in details
>>> and using one in the outward-facing namespace (it is not unnatural if
>>> public API is a proper subset of "all details"). But if the namespace
>>> `detail' actively jumps at you as intended for implementation-specific
>>> things exclusively, why not be explicit and use something like using_std
>>> namespace:
>>>
>>> namespace mylib {
>>> namespace using_std {
>>> using namespace std;
>>> // define stuff heavily using things from std:: , in particular `stuff'
>>> // that is a part of mylib API
>>> }
>>> using using_std::stuff;
>>> }
>>>
>>> Using identifiers beginning with _ in application programs is at least
>>> frown upon by the Standard ("shall not be used otherwise [than by
>>> implementation]"), see 5.10-3.2 in n4830.
>>
>> Identifiers starting with `_` are reserved in the global namespace.
>>
>> Identifiers starting with `_` followed by uppercase letter are reserved
>> everywhere.
>>
>> I don't recall any rule like the one you imply, so I think you're
>> looking at either the C standard or a proposal of some sort.
> I referred to n4830 5.10 (you can call it a proposal but I doubt
> anything will change in this particular regard):
> 
> 3 In addition, some identifiers are reserved for use by C++
> implementations and shall not be used otherwise; no
> diagnostic is required.
> (3.1) — Each identifier that contains a double underscore __ or begins
> with an underscore followed by an
> uppercase letter is reserved to the implementation for any use.
> (3.2) — Each identifier that begins with an underscore is reserved to
> the implementation for use as a name in
> the global namespace.
> 
> Approximately same text was in C++ 11 Standard:
> 
> 17.6.4.3.2 Global names [global.names]
> 1 Certain sets of names and function signatures are always reserved to
> the implementation:
> — Each name that contains a double underscore _ _ or begins with an
> underscore followed by an uppercase
> letter (2.12) is reserved to the implementation for any use.
> — Each name that begins with an underscore is reserved to the
> implementation for use as a name in the
> global namespace.
> 
> So, _ is not just reserved for use as a name in the global namespace but
> is reserved *for use by by C++ implementation* (n4830) or *to the
> implementation* (2011 Standard).

That doesn't follow from what you quote.

What you quote now is what I told you.

In addition, what you quote now does not contain the text you quoted out 
of context earlier.


> bonitas::_ is neither used by C++ implementation nor a name in the
> global namespace so it seems not compliant to either the 2011 Standard
> or n4830 on both fronts.

And this does not make sense.


>>>> However, client code is only meant to use the stuff via the exporting
>>>> namespace(s), here bonitas, which itself is/are clean.
>>>>
>>>> There are countless variations and extensions of the scheme, and there
>>>> is a gotcha about templates that client code is meant to specialize.

- Alf

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

I'd like to have unusing Bonita Montero <Bonita.Montero@gmail.com> - 2019-12-12 12:49 +0100
  Re: I'd like to have unusing "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-12 13:51 +0100
    Re: I'd like to have unusing Öö Tiib <ootiib@hot.ee> - 2019-12-12 05:47 -0800
      Re: I'd like to have unusing "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-12 17:58 +0100
        Re: I'd like to have unusing Öö Tiib <ootiib@hot.ee> - 2019-12-12 09:40 -0800
          Re: I'd like to have unusing "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-13 09:23 +0100
      Re: I'd like to have unusing "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-12 17:58 +0100
    Re: I'd like to have unusing boltar@nowhere.co.uk - 2019-12-12 16:23 +0000
    Re: I'd like to have unusing Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2019-12-25 13:19 -0500
      Re: I'd like to have unusing "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-25 20:09 +0100
        Re: I'd like to have unusing Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2019-12-25 16:37 -0500
          Re: I'd like to have unusing "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-25 22:56 +0100
            Re: I'd like to have unusing Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2019-12-25 17:06 -0500
              Re: I'd like to have unusing Öö Tiib <ootiib@hot.ee> - 2019-12-25 14:14 -0800
                Re: I'd like to have unusing Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2019-12-25 17:28 -0500
                Re: I'd like to have unusing "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-26 00:49 +0100
                Re: I'd like to have unusing Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2019-12-25 19:54 -0500
                Re: I'd like to have unusing "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-26 03:53 +0100
                Re: I'd like to have unusing Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2019-12-25 22:32 -0500
                Re: I'd like to have unusing Öö Tiib <ootiib@hot.ee> - 2019-12-26 03:01 -0800
                Re: I'd like to have unusing Öö Tiib <ootiib@hot.ee> - 2019-12-26 03:20 -0800
                Re: I'd like to have unusing Richard Damon <Richard@Damon-Family.org> - 2019-12-27 11:24 -0500
                Re: I'd like to have unusing Öö Tiib <ootiib@hot.ee> - 2019-12-27 09:22 -0800
                Re: I'd like to have unusing Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2020-01-02 23:47 -0500
                Re: I'd like to have unusing Öö Tiib <ootiib@hot.ee> - 2020-01-02 23:46 -0800
                Re: I'd like to have unusing Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2020-01-04 23:46 -0500
                Re: I'd like to have unusing Richard Damon <Richard@Damon-Family.org> - 2020-01-04 18:43 -0500
                Re: I'd like to have unusing Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2020-01-04 23:55 -0500
  Re: I'd like to have unusing Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-12-12 18:29 +0000
    Re: I'd like to have unusing Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-12-12 18:34 +0000
      Re: I'd like to have unusing Daniel <danielaparker@gmail.com> - 2019-12-12 11:17 -0800
    Re: I'd like to have unusing Bonita Montero <Bonita.Montero@gmail.com> - 2019-12-12 19:40 +0100
      Re: I'd like to have unusing Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-12-12 19:56 +0000
        Re: I'd like to have unusing Bonita Montero <Bonita.Montero@gmail.com> - 2019-12-13 06:35 +0100

csiph-web