Advertisement
Swiftkill

Untitled

Sep 2nd, 2023
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <QDebug>
  2.  
  3. // Can I do better?
  4. namespace google {
  5.     namespace protobuf {
  6.     class MessageLite;
  7.     class Message;
  8.     }
  9. }
  10.  
  11. // Scary syntax because this should compile in TR1 (VS2010)
  12. namespace printFunctions {
  13.     /*!
  14.      *  @brief short-circuit overload for printData to use with ADL
  15.      *
  16.      *      @tparam Msg     message type
  17.      *
  18.      *      @param [in]     PacketNum  associated message id
  19.      *      @param [in]     msg        subj
  20.      */
  21.     template <typename Msg>
  22.     typename std::enable_if<std::is_base_of<::google::protobuf::MessageLite, Msg>::value>::type
  23.         printData(PacketID PacketNum, const Msg& msg)
  24.     {
  25.         qDebug() << "------------ " << msg.GetTypeName().c_str() << " with #" << PacketNum;
  26.     }
  27.  
  28.     template <typename Msg>
  29.     typename std::enable_if_t<std::is_base_of<::google::protobuf::Message, Msg>::value, Msg>::type
  30.         printData(PacketID PacketNum, const Msg & msg)
  31.     {
  32.         qDebug() << "------------ " << msg.GetTypeName().c_str() << " with #" << PacketNum;
  33.         qDebug() << msg.DebugString().c_str();
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement