Skip to content
Snippets Groups Projects

C++26: variadic friends

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Vladislav Antonov
    crtp.cpp 426 B
    // The base class
    template<class Crtp, class MsgT>
    class Receiver { 
      void receive(MsgT) {
        static_cast<Crtp*>(this)->private_ += 1;
      }
    };
    
    
    // The derived class
    template<class MsgT>
    struct Dispatcher :
      public Receiver<Dispatcher<MsgT>, MsgT>
    {
      //_private member exposed to the base class, called Receiver
      using Receiver<Dispatcher, MsgT>::Receiver;
      friend Receiver<Dispatcher, MsgT>;
    
    private:
      int private_;
    };
    crtp_variadic_friends.cpp 550 B
    pack_of_friends.cpp 209 B
    passkey_idiom.cpp 482 B
    passkey_idiom_variadic_friends.cpp 337 B
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment