This question already has an answer here:
How can I get this code to build using XCode/Clang as shipped with OS X 10.10.3?
// A template class for a property that calls a function on property_value_changed
template <typename T, typename V = void>
class PROPERTY_WITH_LISTENER_FUNCTION : public T
{
class LISTENER_FUNCTION : public PROPERTY_LISTENER
{
std::function<void(V)> m_function;
public:
LISTENER_FUNCTION(std::function<void(V)> function)
: m_function(std::move(function)) {}
template <typename V2> void do_call(const PROPERTY &p)
{
m_function(p.get<V2>());
}
template <> void do_call<void>(const PROPERTY &) // <=== Error here
{
m_function();
}
virtual void property_value_changed(const UTILITYDLL::PROPERTY &p)
{
if(m_function) do_call<V>(p);
}
};
LISTENER_FUNCTION m_listener;
public:
template <typename... ARGS>
PROPERTY_WITH_LISTENER_FUNCTION(const String &name,
std::function<void(V)> function,
ARGS&&... args)
: T(name, std::forward<ARGS>(args)...)
, m_listener(std::move(function))
{
add_listener(m_listener);
}
virtual ~PROPERTY_WITH_LISTENER_FUNCTION()
{
remove_listener(m_listener);
}
};
It builds fine in MSVC 2013, but with XCode/Clang I get the error
PropertySet.h:1171:9: error: cannot specialize a function 'do_call' within class scope
void do_call<void>(const PROPERTY &);
^
No amount of juggling seems to be able to persuade Clang to do what it's told. Can anyone come up with a compiling version?
Aucun commentaire:
Enregistrer un commentaire