1

I'm reading through the rapidjson library at the moment, and found this piece of code in stringbuffer.h:

void Put(Ch c) { *stack_.template Push<Ch>() = c; }

where stack_ is defined as

mutable internal::Stack<Allocator> stack_;

and the function Push() is implemented as

template<typename T>
    RAPIDJSON_FORCEINLINE T* Push(size_t count = 1) {
        Reserve<T>(count);
        return PushUnsafe<T>(count);
    }

My question is about the Push(Ch c) function defined at the top. Why is there a template command issued when accessing the Push() member function? Does it serve any purpose besides delivering clarity that Push() is a templated function?

Further, is this some kind of best practice / would you recommend it?

Remy Lebeau
  • 454,445
  • 28
  • 366
  • 620
  • 1
    Possible duplicate: https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords – 김선달 May 07 '21 at 01:36
  • The linked answer addresses my question, thanks! I'll let question stay as reference since it is unclear what needed to be searched for to find the answer. – speed_of_light May 07 '21 at 02:46

0 Answers0