-1

I am asking this question for readability reasons not for implementation.

I haven't found any article explaining any distinction between single prefixed underscore and double prefixed underscore or double prefix and suffix if any.

Is there a special meaning between these different styles that will help with readability? They seem random. Example 1 has all the variables to be only single prefix but then example 2 has the variables double prefixed.

  1. _single

using type = _Template<_Up, _Types...>;

  1. __double

struct __replace_first_arg

  1. __ prefixAndSuffixUnderscore__

namespace std __attribute__((__visibility__("default")))

From the c++ STL container

e.g: 1

namespace std __attribute__((__visibility__("default")))
{

  class __undefined;

  template <typename _Tp, typename _Up>
  struct __replace_first_arg
  {
  };

  template <template <typename, typename...> class _Template, typename _Up,
            typename _Tp, typename... _Types>
  struct __replace_first_arg<_Template<_Tp, _Types...>, _Up>
  {
    using type = _Template<_Up, _Types...>;
  };

e.g: 2

  template <typename _InputIterator, typename _Distance>
  inline constexpr void
  __advance(_InputIterator & __i, _Distance __n, input_iterator_tag)
  {

    do
    {
      if (__builtin_is_constant_evaluated() && !bool(__n >= 0))
        __builtin_unreachable();
    } while (false);
    while (__n--)
      ++__i;
  }

I have read about the conventions for avoiding prefixed underscores in c++ to avoid collision with names inside the STL headers like global macros objects etc. This is not my question.

Ive tried: https://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_02.html

What are the rules about using an underscore in a C++ identifier?

https://manual.gromacs.org/5.1.1/dev-manual/naming.html

Prefix try keyword with two underscore in c++

etc...

Useless
  • 64,155
  • 6
  • 88
  • 132
FredFrugal
  • 75
  • 1
  • 10
  • 4
    the key point about the single prefix is that it is followed by an uppercase letter – Neil Butterworth Nov 11 '22 at 12:14
  • One of your linked questions describes exactly which identifiers are reserved for the implementation. The implementation can use whatever suitable identifiers it likes, you're just asking about style guidelines within that. And `__attribute__` is a compiler extension, so it was decided by the compiler authors. – Useless Nov 11 '22 at 12:14
  • That is: the rules reserving some names for the implementation are the same whether you're asking _which names to avoid in regular code_ (your links) or _why the implementation uses those names_ (your question). Anything else is just the coding style for a particular implementation. – Useless Nov 11 '22 at 12:16
  • @Useless Yes to this: "you're just asking about style guidelines within that". I am trying to figure out if there is special meaning between the different styles for readability. I wish to be able to decipher more easily between different objects if there is a way. Alternatively have someone tell me definitively that its arbitrary and the difference between single and double will not help me figure out what is what. – FredFrugal Nov 11 '22 at 12:18
  • 1
    So have you looked for style guidelines for the particular implementation you're using? You haven't said which it is. It _looks_ like it's using `_InitialCaps` for most types and `__lower_case` for functions and variables, which is conventional enough, although I see exceptions. Are you hoping for something more than that? – Useless Nov 11 '22 at 12:22
  • I am not using any sort of implantation I am reading the standard template library implantation from the container and there is just a lot going on with zero comments explaining what is happening. So my goal is to figure out if there is some meaning behind the reason they decided to write single underscores or double. I do think @NeilButterworth is on to something because every single uppercase seems to be a typename for the template. – FredFrugal Nov 11 '22 at 12:29
  • @Fred that wasn't exactly what i meant - i meant that underscore-uppercase names such as _Type are reserved in the same way as __type, but not the same as _type. also, the standard lib implementation code is not really meant as a learning resource – Neil Butterworth Nov 11 '22 at 12:40
  • I beg to differ and that is not whats in question here. @NeilButterworth – FredFrugal Nov 11 '22 at 12:51
  • With reference to different coding styles you are wandering very close to Opinion Based. ie the opinion of the dev-lead / dev-team for each standard library implementation. – Richard Critten Nov 11 '22 at 12:54
  • Maybe I need to rewrite the question. I am not asking a opinion based question. I am asking if there are rules to the conventions used when they wrote the libraries to help identify curtain objects via the use of single or double prefixed underscores. If the answer in **no it was arbitrary and the underscores are just reserved for the libraries use to avoid name collisions** then that is the answer. I know **m_someMember** is a convention used to convey this is a member variable or something pertaining to the class being manipulated. – FredFrugal Nov 11 '22 at 13:05
  • Given this I am trying to figure out if there where similar conventions used for ease of identification used on the STL. – FredFrugal Nov 11 '22 at 13:05
  • @FredFrugal The only rules are the _"reserved for implementation"_ rules. The reset is up to the opinion of each development team (of their Standard Library implementation). The C++ Standard does not specify any coding conventions outside of _"reserved for implementation"_ – Richard Critten Nov 11 '22 at 13:07
  • @Fred - If you look at the standard document for [std::list](http://eel.is/c++draft/list.syn) you will see that it uses non-reserved names, like `Allocator`, `Predicate` and `pred`. I wouldn't be at all surprised if an actual implementation then uses the reserved names `_Allocator`, `_Predicate`, and `__pred`. You probably shouldn't read anything more into that. And the standard document itself is written by various authors over 25+ years, so isn't consistent either. – BoP Nov 11 '22 at 13:46

1 Answers1

0

Is there a distinction between __lower_case names and _TitleCase names in a standard library implementation?

  • Yes, in the essentially uninteresting sense that they're different names, just like any other names that don't consist of the same characters.

  • Yes, in the sense that some coding style guide may reserve each for different purposes.

  • No, in the sense that nothing about either of the first two senses is special to either names reserved for the implementation or the standard library.

There isn't a single standard library implementation. If your question is about why a given implementation chooses __lower_case for functions and _TitleCase for types, that's a question for that particular implementation's style guide.

The reason that every implementation will prefer identifiers of (one or both of) those two forms is that they're reserved for the implementation.

Your claim that you aren't using any implementation is nonsense: if it compiles, it is an implementation. The standard only specifies an interface and some constraints.

Oh, and the standard library, whether we're discussing the specification or an implementation, is not the STL. The Standard Template Library was an influential precursor to the library incorporated into the first C++ standard in 1998.

Useless
  • 64,155
  • 6
  • 88
  • 132
  • No my question was "**is there** " not "**why**".. I am asking for identification purposes only. As in, If I see a name starting with __ doubleUnderscores "**is that a**" cue that there is a special category that it falls under compared to another with only _ oneUnderscore or __ Prefix&Suffix __. The fact that I am only reading for a better understanding is what i meant by "I am not implementing anything", I am reading std::list.h and was trying to get a better understanding on how they implemented the list. Thanks for the clarification I understand now. – FredFrugal Nov 13 '22 at 14:41