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;
};