0

I'm curious about the STL naming convention. what's the 'p' means in STL templates. For example:

template <class _Fp> class __value_func;

template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
{
    typename aligned_storage<3 * sizeof(void*)>::type __buf_;

    typedef __base<_Rp(_ArgTypes...)> __func;
    __func* __f_;

Does that means type? Tp means "Type", Rp means "Return type", Fp means "Function type"?

jasonxia
  • 321
  • 1
  • 8
  • 2
    These names are implementation details of the particular standard library implementation you're looking at. You can best answer the question by asking your standard library's implementers. – Justin Aug 21 '20 at 01:27
  • Leading underscore might have a special mening defined in the C++ specification. See https://stackoverflow.com/q/228783/440558 for details. – Some programmer dude Aug 21 '20 at 01:33
  • At a guess, I would say the `p` might stand for "parameter". But I don't see how knowing this for sure would be of any benefit. – paddy Aug 21 '20 at 01:36
  • At the very least, you should probably call out the implementation you are looking at instead of "STL". The STL does not specify how its templates must be implemented, so questions about implementation details are really about the implementation, not about the standard. – JaMiT Aug 21 '20 at 03:45
  • 1
    The OP has a genuine curiosity about code found in std implementation. I don't think the downvotes are warranted here. Sure this convention is not a standard convention as the OP assumes, but that's why questions exists, because people aren't born with knowledge. Sure, the question is not really useful to the community, but that is a reason to not upvote. I think we shouldn't tax people for asking questions because the answer is: "it doesn't really matter". If you know the convention doesn't really matter then yes the question is useless to you, but if you don't then the question is justified. – bolov Aug 21 '20 at 05:55
  • 1
    Related (and note how the implementation is called out): [GNU standard library naming conventions](https://stackoverflow.com/questions/50604557/gnu-standard-library-naming-conventions), which deals more with the patterns of naming than with the meaning of "p" in particular. – JaMiT Aug 22 '20 at 06:19

1 Answers1

2

If you look in the standard, the names are usually T, U, R, ArgTypes, etc. But implementers can't use those names because people do stuff like #define T true.

So implementations use identifiers that begin with a leading underscore. However, there is a disappointingly large number of code bases where people have done stuff like #define _N 23. Yes, it's reserved for the implementation. People do it anyway. :-(

So, libc++ (for example), uses _Tp, _Up, _Rp, _ArgTypes etc. There's not a lot of meaning attached to those names. They start with an underscore and a capital letter and they're longer than two characters - and they're similar enough to the names used in the standard that you can match them up.

Marshall Clow
  • 15,972
  • 2
  • 29
  • 45