0

When I read template SignalSlot code below. It uses Delegate::template bind<T, mem_ptr>(&ptr) when calling static method in Function template instead of Delegate::bind<T, mem_ptr>(&ptr) in line delegates.push_back(Delegate::template bind<T, mem_ptr>(&ptr)) to make Function<RT(Args...)>. What is the rule/syntax here? Why do we need use ::template here? Is it a namespace? Thanks.

Function.hh

template <typename RT, typename... Args>
class Function<RT(Args...)>
{
    template <typename T, RT (T::*mem_ptr)(Args...)>
    static inline Function bind(Obs* pointer)
    {
        ...
    }
};

SignalSlot.hh

#include "Function.hh"
template <typename RT, typename... Args>
class SignalSlot<RT(Args...)>
{
public:
    template <typename T, RT (T::*mem_ptr)(Args...)>
    void connect(Obs& ptr)
    {
        const auto address  = std::addressof(ptr);
        auto delegate = std::find_if(delegates.begin(), delegates.end(),
            [&address](auto& iter) { return iter.instance() == address; });

        if (delegates.end() == delegate)
        {
            delegates.push_back(Delegate::template bind<T, mem_ptr>(&ptr));
        }
        .....
    }
    ......

private:
    using Exception = exceptions::SignalSlotException;
    using Delegate  = Function<RT(Args...)>;
    std::vector<Delegate> delegates;
};
leiyc
  • 903
  • 11
  • 23
  • 2
    Please note that you can't add styling or formatting in code snippets. If you want to mark out a specific line, add comments around it, and mention them in the question. – Some programmer dude Jul 20 '23 at 09:32

0 Answers0